I noticed that de declarative statements (directly under class) are ignored when self.fields statements are used.
class ProductForm(ModelForm): class Meta: model = Product exclude = ['order'] # This one is vaporised!!! description = forms.CharField(max_length=2,) def __init__(self, *args, **kwargs): super(ProductForm, self).__init__(*args, **kwargs) # By this one!!! self.fields['description'].max_length = 2 Still would like a regex based check in the declarative one. Anybody done this before? Thanx n greetz Gerard. Gerard Petersen wrote: > Hi All, > > I have a not to exciting app (modelwise) with forms all based on modelform. > Im trying to figure out how to realize form field input validation. Went > through piles of text. But I'm still missing the point (or rather place). > > This works for a date field in a defined modelform sub class: > self.fields['period_start_date'].input_formats = ('%d-%m-%Y',) > > Then if I set this on a charfield: "self.fields['description'].max_length = > 2" and the contents of the field is 3 chars I get an error on form.is_valid() > .. "Exception Type: KeyError, Exception Value: 'max_length'" > > That is correct ... sort of (because it's not valid). I'm just going nuts on > where/how to tell Django to return the form (instance) with a field error > message. Eventually I want to put some of the field data through a regular > expression. > > Elaborate google searches came up empty. And it's not like I'm inventing the > wheel here. > > Thanx a lot for any pointers. > > > Gerard. > > -- urls = { 'fun': 'www.zonderbroodje.nl', 'tech': 'www.gp-net.nl' } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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-users?hl=en -~----------~----~----~----~------~----~------~--~---