Keeping ContentTypes and Permissions Updated without syncdb

In managing releases to a production django project, I find myself using python sqlall APPNAME to put the sql needed in a script for any new models, and then writing the ALTER or DROP statements by hand to also go into the sql scripts.

One thing that not running syncdb on production leaves out are the creation of the content type and permission records (if using django.contrib.auth and django.contrib.contenttypes). It was recommended to me on #django that I look at each of these apps module to see where they hook into the post_syncdb signal.

In doing so I discovered some methods that I could just call from python and keep both my permissions and content types up to date:

from import setup_environ
    import settings
except ImportError:
    import sys
    sys.stderr.write("Couldn't find the module.")


# Add any missing content types
from \
    import create_all_contenttypes 

# Add any missing permissions
from import create_permissions
from django.db.models import get_apps
for app in get_apps():
    create_permissions(app, None, 2)