diff options
| author | Joseph Kocherhans <joseph@jkocherhans.com> | 2006-06-19 15:23:57 +0000 |
|---|---|---|
| committer | Joseph Kocherhans <joseph@jkocherhans.com> | 2006-06-19 15:23:57 +0000 |
| commit | adf4b9311d5d64a2bdd58da50271c121ea22e397 (patch) | |
| tree | a69b3b023595cf1ce67a14c4c1ecd3290d94088e /django/contrib/contenttypes/management.py | |
| parent | e976ed1f7910fad03704f88853c5c5b36cbab134 (diff) | |
multi-auth: Merged to [3151]archive/attic/multi-auth
git-svn-id: http://code.djangoproject.com/svn/django/branches/multi-auth@3152 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib/contenttypes/management.py')
| -rw-r--r-- | django/contrib/contenttypes/management.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py new file mode 100644 index 0000000000..a9174584bc --- /dev/null +++ b/django/contrib/contenttypes/management.py @@ -0,0 +1,24 @@ +""" +Creates content types for all installed models. +""" + +from django.dispatch import dispatcher +from django.db.models import get_models, signals + +def create_contenttypes(app, created_models): + from django.contrib.contenttypes.models import ContentType + app_models = get_models(app) + if not app_models: + return + for klass in app_models: + opts = klass._meta + try: + ContentType.objects.get(app_label=opts.app_label, + model=opts.object_name.lower()) + except ContentType.DoesNotExist: + ct = ContentType(name=str(opts.verbose_name), + app_label=opts.app_label, model=opts.object_name.lower()) + ct.save() + print "Adding content type '%s | %s'" % (ct.app_label, ct.model) + +dispatcher.connect(create_contenttypes, signal=signals.post_syncdb) |
