Fixed #28490 -- Removed unused code in admin.E108 check.
This commit is contained in:
parent
5d9b736fd8
commit
47016adbf5
|
@ -643,54 +643,32 @@ class ModelAdminChecks(BaseModelAdminChecks):
|
||||||
elif hasattr(obj, item):
|
elif hasattr(obj, item):
|
||||||
return []
|
return []
|
||||||
elif hasattr(model, item):
|
elif hasattr(model, item):
|
||||||
# getattr(model, item) could be an X_RelatedObjectsDescriptor
|
|
||||||
try:
|
try:
|
||||||
field = model._meta.get_field(item)
|
field = model._meta.get_field(item)
|
||||||
except FieldDoesNotExist:
|
except FieldDoesNotExist:
|
||||||
try:
|
return []
|
||||||
field = getattr(model, item)
|
|
||||||
except AttributeError:
|
|
||||||
field = None
|
|
||||||
|
|
||||||
if field is None:
|
|
||||||
return [
|
|
||||||
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'." % (
|
|
||||||
label, item, obj.__class__.__name__, model._meta.app_label, model._meta.object_name
|
|
||||||
),
|
|
||||||
obj=obj.__class__,
|
|
||||||
id='admin.E108',
|
|
||||||
)
|
|
||||||
]
|
|
||||||
elif isinstance(field, models.ManyToManyField):
|
|
||||||
return [
|
|
||||||
checks.Error(
|
|
||||||
"The value of '%s' must not be a ManyToManyField." % label,
|
|
||||||
obj=obj.__class__,
|
|
||||||
id='admin.E109',
|
|
||||||
)
|
|
||||||
]
|
|
||||||
else:
|
else:
|
||||||
|
if isinstance(field, models.ManyToManyField):
|
||||||
|
return [
|
||||||
|
checks.Error(
|
||||||
|
"The value of '%s' must not be a ManyToManyField." % label,
|
||||||
|
obj=obj.__class__,
|
||||||
|
id='admin.E109',
|
||||||
|
)
|
||||||
|
]
|
||||||
return []
|
return []
|
||||||
else:
|
else:
|
||||||
try:
|
return [
|
||||||
model._meta.get_field(item)
|
checks.Error(
|
||||||
except FieldDoesNotExist:
|
"The value of '%s' refers to '%s', which is not a callable, "
|
||||||
return [
|
"an attribute of '%s', or an attribute or method on '%s.%s'." % (
|
||||||
# This is a deliberate repeat of E108; there's more than one path
|
label, item, obj.__class__.__name__,
|
||||||
# required to test this condition.
|
model._meta.app_label, model._meta.object_name,
|
||||||
checks.Error(
|
),
|
||||||
"The value of '%s' refers to '%s', which is not a callable, "
|
obj=obj.__class__,
|
||||||
"an attribute of '%s', or an attribute or method on '%s.%s'." % (
|
id='admin.E108',
|
||||||
label, item, obj.__class__.__name__, model._meta.app_label, model._meta.object_name
|
)
|
||||||
),
|
]
|
||||||
obj=obj.__class__,
|
|
||||||
id='admin.E108',
|
|
||||||
)
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
return []
|
|
||||||
|
|
||||||
def _check_list_display_links(self, obj):
|
def _check_list_display_links(self, obj):
|
||||||
""" Check that list_display_links is a unique subset of list_display.
|
""" Check that list_display_links is a unique subset of list_display.
|
||||||
|
|
Loading…
Reference in New Issue