mirror of https://github.com/django/django.git
parent
3918eeb9fd
commit
91c77eeab8
|
@ -101,10 +101,16 @@ def create_permissions(app, created_models, verbosity, db=DEFAULT_DB_ALIAS, **kw
|
||||||
]
|
]
|
||||||
# Validate the permissions before bulk_creation to avoid cryptic
|
# Validate the permissions before bulk_creation to avoid cryptic
|
||||||
# database error when the verbose_name is longer than 50 characters
|
# database error when the verbose_name is longer than 50 characters
|
||||||
|
permission_name_max_length = auth_app.Permission._meta.get_field('name').max_length
|
||||||
|
verbose_name_max_length = permission_name_max_length - 11 # len('Can change ') prefix
|
||||||
for perm in perms:
|
for perm in perms:
|
||||||
if len(perm.name) > 50:
|
if len(perm.name) > permission_name_max_length:
|
||||||
raise exceptions.ValidationError(
|
raise exceptions.ValidationError(
|
||||||
"The verbose_name of %s is longer than 39 characters" % perm.content_type)
|
"The verbose_name of %s is longer than %s characters" % (
|
||||||
|
perm.content_type,
|
||||||
|
verbose_name_max_length,
|
||||||
|
)
|
||||||
|
)
|
||||||
auth_app.Permission.objects.using(db).bulk_create(perms)
|
auth_app.Permission.objects.using(db).bulk_create(perms)
|
||||||
if verbosity >= 2:
|
if verbosity >= 2:
|
||||||
for perm in perms:
|
for perm in perms:
|
||||||
|
|
Loading…
Reference in New Issue