Used model's Options.label/label_lower where applicable.

This commit is contained in:
Mariusz Felisiak 2020-01-29 12:09:20 +01:00 committed by GitHub
parent a45c8d7ad0
commit b7a3a6c9ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 29 deletions

View File

@ -607,8 +607,9 @@ class BaseModelAdminChecks:
except FieldDoesNotExist:
return [
checks.Error(
"The value of '%s' is not a callable, an attribute of '%s', or an attribute of '%s.%s'." % (
label, obj.__class__.__name__, obj.model._meta.app_label, obj.model._meta.object_name
"The value of '%s' is not a callable, an attribute of "
"'%s', or an attribute of '%s'." % (
label, obj.__class__.__name__, obj.model._meta.label,
),
obj=obj.__class__,
id='admin.E035',
@ -731,9 +732,9 @@ class ModelAdminChecks(BaseModelAdminChecks):
checks.Error(
"The value of '%s' refers to '%s', which is not a "
"callable, an attribute of '%s', or an attribute or "
"method on '%s.%s'." % (
"method on '%s'." % (
label, item, obj.__class__.__name__,
obj.model._meta.app_label, obj.model._meta.object_name,
obj.model._meta.label,
),
obj=obj.__class__,
id='admin.E108',
@ -1035,8 +1036,8 @@ class InlineModelAdminChecks(BaseModelAdminChecks):
return [
checks.Error(
"Cannot exclude the field '%s', because it is the foreign key "
"to the parent model '%s.%s'." % (
fk.name, parent_model._meta.app_label, parent_model._meta.object_name
"to the parent model '%s'." % (
fk.name, parent_model._meta.label,
),
obj=obj.__class__,
id='admin.E201',
@ -1113,9 +1114,8 @@ def must_inherit_from(parent, option, obj, id):
def refer_to_missing_field(field, option, obj, id):
return [
checks.Error(
"The value of '%s' refers to '%s', which is not an attribute of '%s.%s'." % (
option, field, obj.model._meta.app_label, obj.model._meta.object_name
),
"The value of '%s' refers to '%s', which is not an attribute of "
"'%s'." % (option, field, obj.model._meta.label),
obj=obj.__class__,
id=id,
),

View File

@ -307,7 +307,7 @@ class ModelDetailView(BaseAdminDocsView):
})
return super().get_context_data(**{
**kwargs,
'name': '%s.%s' % (opts.app_label, opts.object_name),
'name': opts.label,
'summary': title,
'description': body,
'fields': fields,

View File

@ -119,9 +119,10 @@ def check_models_permissions(app_configs=None, **kwargs):
)
errors.append(
checks.Error(
"The verbose_name of model '%s.%s' must be at most %d characters "
"for its builtin permission names to be at most %d characters." % (
opts.app_label, opts.object_name, verbose_name_max_length, permission_name_max_length
"The verbose_name of model '%s' must be at most %d "
"characters for its builtin permission names to be at "
"most %d characters." % (
opts.label, verbose_name_max_length, permission_name_max_length
),
obj=model,
id='auth.E007',
@ -138,11 +139,10 @@ def check_models_permissions(app_configs=None, **kwargs):
)
errors.append(
checks.Error(
"The name of model '%s.%s' must be at most %d characters "
"The name of model '%s' must be at most %d characters "
"for its builtin permission codenames to be at most %d "
"characters." % (
opts.app_label,
opts.object_name,
opts.label,
model_name_max_length,
permission_codename_max_length,
),
@ -156,8 +156,9 @@ def check_models_permissions(app_configs=None, **kwargs):
if len(name) > permission_name_max_length:
errors.append(
checks.Error(
"The permission named '%s' of model '%s.%s' is longer than %d characters." % (
name, opts.app_label, opts.object_name, permission_name_max_length
"The permission named '%s' of model '%s' is longer "
"than %d characters." % (
name, opts.label, permission_name_max_length,
),
obj=model,
id='auth.E008',
@ -167,11 +168,10 @@ def check_models_permissions(app_configs=None, **kwargs):
if len(codename) > permission_codename_max_length:
errors.append(
checks.Error(
"The permission codenamed '%s' of model '%s.%s' is "
"The permission codenamed '%s' of model '%s' is "
"longer than %d characters." % (
codename,
opts.app_label,
opts.object_name,
opts.label,
permission_codename_max_length,
),
obj=model,
@ -183,9 +183,7 @@ def check_models_permissions(app_configs=None, **kwargs):
errors.append(
checks.Error(
"The permission codenamed '%s' clashes with a builtin permission "
"for model '%s.%s'." % (
codename, opts.app_label, opts.object_name
),
"for model '%s'." % (codename, opts.label),
obj=model,
id='auth.E005',
)
@ -193,9 +191,8 @@ def check_models_permissions(app_configs=None, **kwargs):
elif codename in codenames:
errors.append(
checks.Error(
"The permission codenamed '%s' is duplicated for model '%s.%s'." % (
codename, opts.app_label, opts.object_name
),
"The permission codenamed '%s' is duplicated for "
"model '%s'." % (codename, opts.label),
obj=model,
id='auth.E006',
)

View File

@ -225,7 +225,7 @@ def sort_dependencies(app_list):
raise RuntimeError(
"Can't resolve dependencies for %s in serialized app list." %
', '.join(
'%s.%s' % (model._meta.app_label, model._meta.object_name)
model._meta.label
for model, deps in sorted(skipped, key=lambda obj: obj[0].__name__)
)
)

View File

@ -307,7 +307,7 @@ class Options:
return '<Options for %s>' % self.object_name
def __str__(self):
return "%s.%s" % (self.app_label, self.model_name)
return self.label_lower
def can_migrate(self, connection):
"""