Opened 12 years ago

Closed 11 years ago

#20465 closed New feature (needsinfo)

ModelAdmin.formfield_overrides should look at field attributes

Reported by: Marek Stępniowski Owned by: nobody
Component: contrib.admin Version: dev
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

ModelAdmin.formfield_overrides should look at field attributes in addition to field class, when choosing which widget to use in template. The most important use case here is the choices attribute, as it's likely that user will want to render fields with choices differently (i.e. as select) than fields without choices (which can be a normal input).

After #19303 is merged, current mechanism will allow users to override widget choice for all fields with a certain class. It won't be possible to choose different widget for normal fields and fields with choices, short of overriding the ModelForm. That's not optimal.

Change History (2)

comment:1 by Simon Meers, 12 years ago

As stated in the / docs, formfield_overrides "provides a quick-and-dirty way to override some of the Field options for use in the admin". If you want to do something more complicated than a simple per-field-class override, you should look into overriding ModelAdmin.formfield_for_dbfield. Whilst not overly elegant, it will allow you to completely customise the form fields based on whatever properties you like without "overriding the ModelForm". You may also be interested in / ModelAdmin.formfield_for_choice_field in this instance.

Feel free to propose details of a more elegant solution, though please bear in mind backwards-compatibility concerns. You may also find the details and outcome of #17924 relevant, involving a similar proposal for ModelForms in general.

Last edited 12 years ago by Simon Meers (previous) (diff)

comment:2 by Tim Graham, 11 years ago

Resolution: needsinfo
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top