Used model's Options.label where applicable.

Follow up to b7a3a6c9ef.
This commit is contained in:
Mariusz Felisiak 2020-12-29 08:56:39 +01:00 committed by GitHub
parent c76d51b3ad
commit ce30e750e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 35 deletions

View File

@ -28,9 +28,7 @@ class GenericInlineModelAdminChecks(InlineModelAdminChecks):
if not gfks: if not gfks:
return [ return [
checks.Error( checks.Error(
"'%s.%s' has no GenericForeignKey." % ( "'%s' has no GenericForeignKey." % obj.model._meta.label,
obj.model._meta.app_label, obj.model._meta.object_name
),
obj=obj.__class__, obj=obj.__class__,
id='admin.E301' id='admin.E301'
) )
@ -42,8 +40,8 @@ class GenericInlineModelAdminChecks(InlineModelAdminChecks):
except FieldDoesNotExist: except FieldDoesNotExist:
return [ return [
checks.Error( checks.Error(
"'ct_field' references '%s', which is not a field on '%s.%s'." % ( "'ct_field' references '%s', which is not a field on '%s'." % (
obj.ct_field, obj.model._meta.app_label, obj.model._meta.object_name obj.ct_field, obj.model._meta.label,
), ),
obj=obj.__class__, obj=obj.__class__,
id='admin.E302' id='admin.E302'
@ -55,8 +53,8 @@ class GenericInlineModelAdminChecks(InlineModelAdminChecks):
except FieldDoesNotExist: except FieldDoesNotExist:
return [ return [
checks.Error( checks.Error(
"'ct_fk_field' references '%s', which is not a field on '%s.%s'." % ( "'ct_fk_field' references '%s', which is not a field on '%s'." % (
obj.ct_fk_field, obj.model._meta.app_label, obj.model._meta.object_name obj.ct_fk_field, obj.model._meta.label,
), ),
obj=obj.__class__, obj=obj.__class__,
id='admin.E303' id='admin.E303'
@ -71,8 +69,8 @@ class GenericInlineModelAdminChecks(InlineModelAdminChecks):
return [ return [
checks.Error( checks.Error(
"'%s.%s' has no GenericForeignKey using content type field '%s' and object ID field '%s'." % ( "'%s' has no GenericForeignKey using content type field '%s' and object ID field '%s'." % (
obj.model._meta.app_label, obj.model._meta.object_name, obj.ct_field, obj.ct_fk_field obj.model._meta.label, obj.ct_field, obj.ct_fk_field,
), ),
obj=obj.__class__, obj=obj.__class__,
id='admin.E304' id='admin.E304'

View File

@ -70,8 +70,7 @@ class GenericForeignKey(FieldCacheMixin):
def __str__(self): def __str__(self):
model = self.model model = self.model
app = model._meta.app_label return '%s.%s' % (model._meta.label, self.name)
return '%s.%s.%s' % (app, model._meta.object_name, self.name)
def check(self, **kwargs): def check(self, **kwargs):
return [ return [
@ -343,9 +342,8 @@ class GenericRelation(ForeignObject):
return [ return [
checks.Error( checks.Error(
"The GenericRelation defines a relation with the model " "The GenericRelation defines a relation with the model "
"'%s.%s', but that model does not have a GenericForeignKey." % ( "'%s', but that model does not have a GenericForeignKey."
target._meta.app_label, target._meta.object_name % target._meta.label,
),
obj=self, obj=self,
id='contenttypes.E004', id='contenttypes.E004',
) )

View File

@ -195,9 +195,8 @@ class Command(BaseCommand):
) )
# psycopg2 raises ValueError if data contains NUL chars. # psycopg2 raises ValueError if data contains NUL chars.
except (DatabaseError, IntegrityError, ValueError) as e: except (DatabaseError, IntegrityError, ValueError) as e:
e.args = ("Could not load %(app_label)s.%(object_name)s(pk=%(pk)s): %(error_msg)s" % { e.args = ("Could not load %(object_label)s(pk=%(pk)s): %(error_msg)s" % {
'app_label': obj.object._meta.app_label, 'object_label': obj.object._meta.label,
'object_name': obj.object._meta.object_name,
'pk': obj.object.pk, 'pk': obj.object.pk,
'error_msg': e, 'error_msg': e,
},) },)

View File

@ -183,8 +183,7 @@ class Field(RegisterLookupMixin):
if not hasattr(self, 'model'): if not hasattr(self, 'model'):
return super().__str__() return super().__str__()
model = self.model model = self.model
app = model._meta.app_label return '%s.%s' % (model._meta.label, self.name)
return '%s.%s.%s' % (app, model._meta.object_name, self.name)
def __repr__(self): def __repr__(self):
"""Display the module, class, and name of the field.""" """Display the module, class, and name of the field."""

View File

@ -172,14 +172,10 @@ class RelatedField(FieldCacheMixin, Field):
if (self.remote_field.model not in self.opts.apps.get_models() and if (self.remote_field.model not in self.opts.apps.get_models() and
not isinstance(self.remote_field.model, str) and not isinstance(self.remote_field.model, str) and
self.remote_field.model._meta.swapped): self.remote_field.model._meta.swapped):
model = "%s.%s" % (
self.remote_field.model._meta.app_label,
self.remote_field.model._meta.object_name
)
return [ return [
checks.Error( checks.Error(
"Field defines a relation with the model '%s', which has " "Field defines a relation with the model '%s', which has "
"been swapped out." % model, "been swapped out." % self.remote_field.model._meta.label,
hint="Update the relation to point at 'settings.%s'." % self.remote_field.model._meta.swappable, hint="Update the relation to point at 'settings.%s'." % self.remote_field.model._meta.swappable,
obj=self, obj=self,
id='fields.E301', id='fields.E301',
@ -1479,18 +1475,12 @@ class ManyToManyField(RelatedField):
if isinstance(self.remote_field.model, str): if isinstance(self.remote_field.model, str):
kwargs['to'] = self.remote_field.model kwargs['to'] = self.remote_field.model
else: else:
kwargs['to'] = "%s.%s" % ( kwargs['to'] = self.remote_field.model._meta.label
self.remote_field.model._meta.app_label,
self.remote_field.model._meta.object_name,
)
if getattr(self.remote_field, 'through', None) is not None: if getattr(self.remote_field, 'through', None) is not None:
if isinstance(self.remote_field.through, str): if isinstance(self.remote_field.through, str):
kwargs['through'] = self.remote_field.through kwargs['through'] = self.remote_field.through
elif not self.remote_field.through._meta.auto_created: elif not self.remote_field.through._meta.auto_created:
kwargs['through'] = "%s.%s" % ( kwargs['through'] = self.remote_field.through._meta.label
self.remote_field.through._meta.app_label,
self.remote_field.through._meta.object_name,
)
# If swappable is True, then see if we're actually pointing to the target # If swappable is True, then see if we're actually pointing to the target
# of a swap. # of a swap.
swappable_setting = self.swappable_setting swappable_setting = self.swappable_setting

View File

@ -185,9 +185,8 @@ class ManagerDescriptor:
if cls._meta.swapped: if cls._meta.swapped:
raise AttributeError( raise AttributeError(
"Manager isn't available; '%s.%s' has been swapped for '%s'" % ( "Manager isn't available; '%s' has been swapped for '%s'" % (
cls._meta.app_label, cls._meta.label,
cls._meta.object_name,
cls._meta.swapped, cls._meta.swapped,
) )
) )