On Thu, Nov 12, 2009 at 2:23 PM, rebus_ <r.dav...@gmail.com> wrote:
> You can add custom clean methods in your form: > > class Event (models.Model): > start_date = models.DateField() > end_date = models.DateField() > > def clean(self): > start = self.cleaned_data.get('start_date', False) > end = self.cleaned_data.get('end_date', False) > if not start or not end: > raise forms.ValidationError('message') > if start > end: > raise forms.ValidationError('start is greater then end') > return self.cleaned_data > > This is just an example code. > > Using this approach validation errors will not be associated with and > field. > You could write clean_start_date and clean_end_date methods which > would evaluate each field and all validation errors would be > associated with specific field. > > To learn more about form validation read [1] or [2]: > > [1] http://docs.djangoproject.com/en/dev/ref/forms/validation/ > [2] > http://code.djangoproject.com/browser/django/trunk/docs/ref/forms/validation.txt > > Thanks! This is actually what I have done. The only problem is that I do not always use forms to supply data (sometimes I import from CVS) and would like to avoid doing the validation at two different points. For the time being, I guess this will do Cheers Dirk -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=.