﻿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
17924	Proposal: DRY/elegant/flexible ModelForm field attribute overrides	Simon Meers	Simon Meers	"Currently overriding certain attributes of fields in `ModelForm`s is somewhat limited/inflexible unless you resort to using the undocumented and inelegant `formfield_callback` functionality.

For example, you can change a field's widget class quite elegantly by using the `ModelForm.Meta.widgets` dictionary. However if you want to change a different aspect such as `label`, `required`, `form_class`, etc you have to either:

* replace the field with a manually defined one and lose all attributes inherited from the corresponding `Models.Field` (as described in the [https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-field-types-or-widgets caveat note])
* define a `formfield_callback` function (undocumented / inelegant)

Two solutions spring to mind:

* addition of `labels`, `required`, `form_classes` analogues of `ModelForm.Meta.widgets` (I don't like where this leads)
* addition of an `overrides` attribute to `ModelForm.Meta` which can encompass the existing `widgets` functionality (potentially deprecatable) but also provides the ability to override other field attributes. For example

{{{
class MyForm(forms.ModelForm):
    class Meta:
        overrides = {
            'description': {
                'widget': forms.Textarea,
                'label': 'Message',
            },
            'start_date': {'label': 'Date Range'},
            'end_date': {'label': 'to'},
            'type': {
                'form_class': ModelChoiceFieldWithDescriptions,
                'empty_label': None,
            },
        }
}}}

This keeps inherited attributes DRY, but allows easy/elegant overriding of arbitrary field attributes. The patch for this is actually quite simple, which I'm very happy to polish and provide, I just thought I'd first seek out opinions regarding the approach before investing time in it."	New feature	closed	Forms	1.3	Normal	wontfix	modelform, attributes, override, DRY	charette.s@… real.human@…	Accepted	0	1	1	0	0	0
