ModelAdmin API (formfield_for_*)

64 views
Skip to first unread message

Yoong Kang Lim

unread,
Jan 23, 2016, 12:03:41 PM1/23/16
to Django developers (Contributions to Django itself)
Currently the BaseModelAdmin class has a method called formfield_for_dbfield which has a conditional block that in turn calls different formfield_for_* methods depending on the type of database field it is handling. In order to do any custom logic to these fields we need to override these methods and/or pass in some arguments as kwargs to override attributes of the form field.

In my opinion, a more natural way is to let different objects handle the customization, rather than BaseModelAdmin. I'm proposing AdminField classes with a consistent API that others can subclass from and swap with the defaults if they desire. 

I've done so preliminary work that you can see in this PR:

Tim Graham

unread,
Jan 23, 2016, 12:14:22 PM1/23/16
to Django developers (Contributions to Django itself)
For a quick glance, the high-level idea looks okay (subject to a deprecation path, of course), however, in my mind it would be more useful to try to move toward enhancing the forms library itself (if possible) so that less admin-specific code is needed. Have you thought about this at all?

Yoong Kang Lim

unread,
Jan 23, 2016, 11:14:05 PM1/23/16
to Django developers (Contributions to Django itself)
Good point, I suppose it'll be better if it were in forms. I'll be looking into this.
Reply all
Reply to author
Forward
0 new messages