Fixed #1802 -- Fixed database integrity error when creating permission objects after renaming a model
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3172 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
37addba352
commit
fb1c01b103
|
@ -25,11 +25,9 @@ def create_permissions(app, created_models):
|
||||||
for klass in app_models:
|
for klass in app_models:
|
||||||
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:
|
p, created = Permission.objects.get_or_create(codename=codename, content_type__pk=ctype.id,
|
||||||
Permission.objects.get(name=name, codename=codename, content_type__pk=ctype.id)
|
defaults={'name': name, 'content_type': ctype})
|
||||||
except Permission.DoesNotExist:
|
if created:
|
||||||
p = Permission(name=name, codename=codename, content_type=ctype)
|
|
||||||
p.save()
|
|
||||||
print "Adding permission '%s'" % p
|
print "Adding permission '%s'" % p
|
||||||
|
|
||||||
def create_superuser(app, created_models):
|
def create_superuser(app, created_models):
|
||||||
|
|
Loading…
Reference in New Issue