﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25374	Admin system check prevents dynamic ModelAdmin attributes	Malcolm Box	nobody	"With a ModelAdmin that defines some dynamic attributes via __getattr__, and uses these in fields or readonly_fields (or list_display etc), the system check admin.E035 error is raised.

Simple example below - note that in the full use case, the __getattr__ is part of a baseclass/mixin so it can be reused across multiple ModelAdmins :

{{{
class ExampleAdmin(models.ModelAdmin):
     fields = ['image_thumbnail', 'image', 'another_image', 'another_image_thumbnail']
     readonly_fields = ['image_thumbnail', 'another_image_thumbnail']
     list_display = ['image_thumbnail']

     def __getattr__(self, name):
         if name.endswith('_thumbnail'):
              def thumbnail_function(obj):
                    # ... generate appropriate thumbnail method
              return thumbnail_function
         else:
             raise AttributeError
}}}

This code worked fine in 1.6, and it works fine in 1.8/1.9 if the system check is silenced.

The root cause is that the system check uses the class to verify that fields exist rather than an instance:

https://github.com/django/django/blob/dae81c6ec62a76c1f28745ae3642c2d4a37ce259/django/contrib/admin/sites.py#L106-L110

Which means that anything that's defined on an instance of the ModelAdmin but not on the class itself will fail the check, whereas the code will work.

According to the documentation, for readonly_fields, the values are ""similar to list_display"", and list_display is documented to allow ""A string representing an attribute on the ModelAdmin"". However this fails system check admin.E108

There's two issues raised by this:

* Is it reasonable for system checks to fail when the actual code will work - or is this *always* a bug in the system check?
* In this specific case, should the admin system check inspect ModelAdmin instances rather than classes so that the check is closer to the implementation.



"	Bug	closed	contrib.admin	dev	Normal	fixed		Simon Charette	Ready for checkin	1	0	0	0	0	0
