#34508: Admin Checks Reversed FKs.( modified check_list_display function )
-------------------------------+--------------------------------------
Reporter: sanju3110 | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 4.2
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):
* status: new => closed
* resolution: => needsinfo
Old description:
> from django.contrib.admin.checks import E109
> from django.core.checks import Error
>
> def check_list_display(app_configs, **kwargs):
> errors = []
>
> for model, model_admin in all_admins.items():
> list_display = getattr(model_admin, 'list_display', [])
> for field_name in list_display:
> try:
>
> model._meta.get_field(field_name)
> except FieldDoesNotExist:
> try:
>
> related_model = getattr(model,
> field_name).related_model
> related_field = getattr(related_model,
> model._meta.model_name.lower())
> if not isinstance(related_field, ForeignObjectRel):
> raise AttributeError
> except (AttributeError, FieldDoesNotExist):
> errors.append(Error(
> 'The value of \'list_display\' must be a list or
> tuple of field names or callables that are '
> 'valid on the model, or a string representing a
> model method. '
> 'The field name \'%s\' is not a valid field name
> on the model \'%s\'.'
> % (field_name, model._meta.label),
> obj=model_admin.__class__,
> id=E109,
> ))
>
> return errors
New description:
{{{
from django.contrib.admin.checks import E109
from django.core.checks import Error
def check_list_display(app_configs, **kwargs):
errors = []
for model, model_admin in all_admins.items():
list_display = getattr(model_admin, 'list_display', [])
for field_name in list_display:
try:
model._meta.get_field(field_name)
except FieldDoesNotExist:
try:
related_model = getattr(model,
field_name).related_model
related_field = getattr(related_model,
model._meta.model_name.lower())
if not isinstance(related_field, ForeignObjectRel):
raise AttributeError
except (AttributeError, FieldDoesNotExist):
errors.append(Error(
'The value of \'list_display\' must be a list or
tuple of field names or callables that are '
'valid on the model, or a string representing a
model method. '
'The field name \'%s\' is not a valid field name
on the model \'%s\'.'
% (field_name, model._meta.label),
obj=model_admin.__class__,
id=E109,
))
return errors
}}}
--
Comment:
Thanks for the report, however I really don't have any idea what you are
trying to report. Please follow our
[https://docs.djangoproject.com/en/dev/internals/contributing/bugs-and-
features/#reporting-bugs bug reporting guidelines] and ''"write complete,
reproducible, specific bug reports. You must include a clear, concise
description of the problem, and a set of instructions for replicating
it."''
--
Ticket URL: <https://code.djangoproject.com/ticket/34508#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070187a8736cc1-ced3efa3-887e-49f9-b4c1-8fa3b2662611-000000%40eu-central-1.amazonses.com.