Opened 19 months ago

Last modified 19 months ago

#34508 closed Uncategorized

Admin Checks Reversed FKs.( modified check_list_display function ) — at Initial Version

Reported by: sanju3110 Owned by: nobody
Component: Uncategorized Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top