On 08/09/06 22:15, DavidA wrote: > I'm sure I'm just misunderstanding how manipulators and validators > work, but I can't see the right way to do this: I want to support more > formats for a DateField then just 'YYYY-MM-DD' (which is checked in > DateField by isValidANSIDate). > > It seems like I can add *more restrictive* validators but can't > *replace* the existing ones with more relaxed validators. > > So instead I've manually checked and converted the value in my view > right before the call to manipulator.get_validation_errors (I validate > it, and if its a valid date, I convert it to a string in the format > 'YYYY-MM-DD' and put it back in the new_data dict so it *will* pass the > isValidANSIDate check.) > > This seems kludgy to me, and 9 times out of 10, when something looks > kludgy in my Django code, its because I'm missing something obvious. > > Thanks in advance, > -Dave >
Hi Dave I've had similar problems and solved them like this: myproject/validators.py %<------------------------------ from django.utils.translation import gettext_lazy as _ from django.core.validators import * import re my_ansi_date_re = re.compile('put regexp here') def isValidANSIDate(field_data, all_data): if not my_ansi_date_re.search(field_data): raise ValidationError, _('Enter a valid date in PUT FORMAT DESCRIPTION HERE format.') [more custom or overridden validators] %<------------------------------ And in my models I do: from myproject import validators instead of from django.core import validators Like this I can override any of djangos validators or add custom ones and they are all still available in one namespace. hope this helps cheers Steven --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---