I understand the motivation for this, and support the idea, but I
think the implementation is a little repetitive:

class MyForm(forms.ModelForm):
    class Meta:
        fields = # LIST OF FIELDS
        widgets = # DICT OF FIELD NAMES : WIDGETS

Why not do something like this:

class MyForm(forms.ModelForm):
    class Meta:
        fields = {
            'text': forms.CharField(widget=forms.Textarea(), ...),
            'other_field': None,
        }

Where the 'None' indicates "do the default". This way you could
completely redefine the behaviour of the model form. Putting in a list
or tuple would just do what it's always done.

Regards,
Zack

On Sep 29, 11:07 am, SmileyChris <[EMAIL PROTECTED]> wrote:
> Bah, it was just prototype code but point taken ;)
>
> I do feel like it leads to slippery slope though. LikeMichael said,
> "why stop at widgets?" I often need to change labels and help text
> too.
>
> On Sep 29, 8:56 pm, Ivan Sagalaev <[EMAIL PROTECTED]> wrote:
>
> > SmileyChris wrote:
> > > I've always just done this by doing:
>
> > > MyForm(ModelForm)
> > >     model = MyModel
> > >     def __init__(self, *args, **kwargs):
> > >         self.fields['name'].widget = Textarea()   # or whatever
>
> > You've forgot to call `super` :-). I know that it's only an example but
> > it adds another line and also shows that such things can easily be
> > forgotten in real code.
>
> > > Do we really need another way of doing this? Or am I overlooking
> > > something that this new method introduces?
>
> > I've addressed this exact thing my first email on subject, so quoting
> > myself:
>
> > > Here the problem is that it has enough boilerplate code to be, shall we
> > > say, not beautiful. And also it defeats nice declarative nature of a
> > > ModelForm.
>
> > So, yes, it's not the end of the world but it's the same convenience as
> > `fields` or `exclude` that all could be simulated in __init__.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to