Skip to content

Commit

Permalink
Fixed #1856 -- install content-type entries and auth permissions for
Browse files Browse the repository at this point in the history
models regardless of the presence of an inner Admin class. Patch from Mathew
Flanagan.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3148 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Jun 19, 2006
1 parent c6dc708 commit 2da4c41
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 0 additions & 2 deletions django/contrib/auth/management.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ def create_permissions(app, created_models):
if not app_models: if not app_models:
return return
for klass in app_models: for klass in app_models:
if not klass._meta.admin:
continue
ctype = ContentType.objects.get_for_model(klass) ctype = ContentType.objects.get_for_model(klass)
for codename, name in _get_all_permissions(klass._meta): for codename, name in _get_all_permissions(klass._meta):
try: try:
Expand Down
24 changes: 24 additions & 0 deletions django/contrib/contenttypes/management.py
Original file line number Original file line Diff line number Diff line change
@@ -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)

0 comments on commit 2da4c41

Please sign in to comment.