﻿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
13769	ModelForm: override default field attributes	Rolando Espinoza La fuente	asenchi	"The common way to alter fields attributes seems to be overriding ModelForm `__init__`, like:

{{{
#!python
class FooForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(FooForm, self).__init__(*args, **kwargs)
        self['field'].attr = ""foo""
}}}

In #11925 was added the `widget` Meta attribute. In the same way could be provided a mechanism to override default field attributes.

The patch attached adds support for `Meta.fields_attrs`. For example:

{{{
#!python
class Foo(models.Model):
    user = models.ForeignKey(User)

class FooForm(forms.ModelForm):
    """"""Renders a select widget with ""-----"" as first option and display all users""""""
    class Meta:
        model = Foo

class StaffFooForm(forms.ModelForm):
    """"""Renders a select widget without empty option and only display staff users""""""
    class Meta:
        model = Foo
        fields_attrs = {
            'user': {
                'empty_label': None,
                'queryset': User.objects.filter(is_staff=True),
            },
        }
}}}"	New feature	closed	Forms	dev	Normal	wontfix	modelform fields_attrs		Design decision needed	1	0	0	0	0	0
