Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1802 -- Fixed database integrity error when creating permissio…

…n objects after renaming a model

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3172 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fb1c01b1038cbba421aaaf5b53da5bb507cc9b48 1 parent 37addba
Adrian Holovaty authored June 20, 2006

Showing 1 changed file with 3 additions and 5 deletions. Show diff stats Hide diff stats

  1. 8  django/contrib/auth/management.py
8  django/contrib/auth/management.py
@@ -25,11 +25,9 @@ def create_permissions(app, created_models):
25 25
     for klass in app_models:
26 26
         ctype = ContentType.objects.get_for_model(klass)
27 27
         for codename, name in _get_all_permissions(klass._meta):
28  
-            try:
29  
-                Permission.objects.get(name=name, codename=codename, content_type__pk=ctype.id)
30  
-            except Permission.DoesNotExist:
31  
-                p = Permission(name=name, codename=codename, content_type=ctype)
32  
-                p.save()
  28
+            p, created = Permission.objects.get_or_create(codename=codename, content_type__pk=ctype.id,
  29
+                defaults={'name': name, 'content_type': ctype})
  30
+            if created:
33 31
                 print "Adding permission '%s'" % p
34 32
 
35 33
 def create_superuser(app, created_models):

0 notes on commit fb1c01b

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