diff options
| author | Hunter Richards <hunter@counsyl.com> | 2017-08-12 18:56:07 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-10-02 13:04:42 -0400 |
| commit | 47016adbf54b54143d4cf052eeb29fc72d27e6b1 (patch) | |
| tree | 61392e30acd2be501f212eb01600afb94723ea74 | |
| parent | 5d9b736fd8e09e273fb5aeeca0da268ecea5f1fd (diff) | |
Fixed #28490 -- Removed unused code in admin.E108 check.
| -rw-r--r-- | django/contrib/admin/checks.py | 62 |
1 files changed, 20 insertions, 42 deletions
diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py index a9398db7e7..c8e05bde7c 100644 --- a/django/contrib/admin/checks.py +++ b/django/contrib/admin/checks.py @@ -643,54 +643,32 @@ class ModelAdminChecks(BaseModelAdminChecks): elif hasattr(obj, item): return [] elif hasattr(model, item): - # getattr(model, item) could be an X_RelatedObjectsDescriptor try: field = model._meta.get_field(item) except FieldDoesNotExist: - try: - 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: return [] - else: - try: - model._meta.get_field(item) - except FieldDoesNotExist: - return [ - # This is a deliberate repeat of E108; there's more than one path - # required to test this condition. - 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', - ) - ] 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 [] + else: + 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', + ) + ] def _check_list_display_links(self, obj): """ Check that list_display_links is a unique subset of list_display. |
