On 18/07/11 14:33, Tom Evans wrote: > I don't see why this is considered hacky or anti-DRY. > > Eg: > > class FooForm(forms.ModelForm, StripWhiteSpaceMixin): > class Meta: > strip_whitespace_fields = ( 'username', ) > model = Foo
This one would be OK, I hadn't thought about that. I guess I would be +0 for the 'strip_whitespace_fields' attribute and functionality added to the Form class, so that it could be used with any Form or ModelForm. Unfortunately we don't yet have 'Meta' on Form, only on ModelForm. I think this could be fixed - we would probably need a 'FormOptions' class, and the existing 'ModelFormOptions' should inherit from that. It might require some thought to get it to work correctly for the case of multiple inheritance. > class FooForm(forms.ModelForm): > username = forms.CharField(strip_whitespace=True) > class Meta: > model = Foo This is not very DRY because the 'CharField' is duplicating something that can be deduced from the model (and there might be other attributes too, like max_length). Doing this correctly for a model with lots of fields would be tedious. Luke -- "Alcohol and calculus don't mix: never drink and derive." Luke Plant || http://lukeplant.me.uk/ -- 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 django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.