Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1856 -- install content-type entries and auth permissions for

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...
commit 2da4c4111ea359ee79ccfdf39167116f232ef8cb 1 parent c6dc708
Malcolm Tredinnick authored June 19, 2006
2  django/contrib/auth/management.py
@@ -23,8 +23,6 @@ def create_permissions(app, created_models):
23 23
     if not app_models:
24 24
         return
25 25
     for klass in app_models:
26  
-        if not klass._meta.admin:
27  
-            continue
28 26
         ctype = ContentType.objects.get_for_model(klass)
29 27
         for codename, name in _get_all_permissions(klass._meta):
30 28
             try:
24  django/contrib/contenttypes/management.py
... ...
@@ -0,0 +1,24 @@
  1
+"""
  2
+Creates content types for all installed models.
  3
+"""
  4
+
  5
+from django.dispatch import dispatcher
  6
+from django.db.models import get_models, signals
  7
+
  8
+def create_contenttypes(app, created_models):
  9
+    from django.contrib.contenttypes.models import ContentType
  10
+    app_models = get_models(app)
  11
+    if not app_models:
  12
+        return
  13
+    for klass in app_models:
  14
+        opts = klass._meta
  15
+        try:
  16
+            ContentType.objects.get(app_label=opts.app_label,
  17
+                model=opts.object_name.lower())
  18
+        except ContentType.DoesNotExist:
  19
+            ct = ContentType(name=str(opts.verbose_name),
  20
+                app_label=opts.app_label, model=opts.object_name.lower())
  21
+            ct.save()
  22
+            print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
  23
+
  24
+dispatcher.connect(create_contenttypes, signal=signals.post_syncdb)

0 notes on commit 2da4c41

Please sign in to comment.
Something went wrong with that request. Please try again.