My use case is that I'd like to edit the `widgets` of a subclassed
form.Form, the only way I can currently do this is by overriding the
entire field or by overriding `__init__()`
Example:
{{{
class MyAuthenticationForm(django.contrib.auth.forms.AuthenticationForm):
class Meta:
wigets = {
'username' : MyFancyWidget()
}
}}}
Right now, I have to do something like (which isn't especially DRY):
{{{
class MyAuthenticationForm(django.contrib.auth.forms.AuthenticationForm):
def __init__(self, *args, **kwargs):
super(MyAuthenticationForm, self).__init__(self, *args, **kwargs)
self.fields['username'].widget = MyFancyWidget()
}}}
I argue that a form's `Meta` class will be a familiar concept to most
django developers (as `ModelForms` are commonly used), and so extending to
`forms.Form` would be natural.
Of course, if `Meta` were used for plain old `forms.Form`, then you could
also use it as a means to exclude fields in the parent form (e.g. in this
case you could do something like
{{{
class Meta:
exclude = ('password',)
}}}
(not that that would be any use in this case)
--
Ticket URL: <https://code.djangoproject.com/ticket/23236>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
`ModelFormMetaclass` is very complex. I don't think adding it to `Form` is
a good idea.
--
Ticket URL: <https://code.djangoproject.com/ticket/23236#comment:1>
Comment (by bmispelon):
I don't see what's "un-DRY" about extending the `__init__()` method and
setting up the widget there.
I like the plain `Form`'s (relative) simplicity and lack of a "magic"
`Meta` class.
Overriding things in `__init__()` is the normal Python way of doing
things.
All-in-all, I'm -0 on the idea.
--
Ticket URL: <https://code.djangoproject.com/ticket/23236#comment:2>
* status: new => closed
* resolution: => wontfix
--
Ticket URL: <https://code.djangoproject.com/ticket/23236#comment:3>