I am having trouble finding documentation on how to add custom
validation to a custom model field.

example:

class PostalField(models.CharField):
        def __init__(self,*args,**kwargs):
                kwargs['max_length']= 6
                super(PostalField, self).__init__(*args, **kwargs)

        def get_internal_type(self):
                return "CharField"


now when I save from the admin with this field it only validates like
a CharField.
How do I fix this to use some function like below.

        def validate(self):
                pattern = re.compile("([A-Z,a-z][0-9]){3}")
                if not pattern.match(value):
                        raise forms.ValidationError('Not A valid Postal Code')
--~--~---------~--~----~------------~-------~--~----~
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