thanks for your reply!
i resolved using this code in the models.py before save():
def save(self):
if len(self.title)<6:
raise ValidationError("cannot be blank or small than 6
byte!")
it works for me!
but i find this code in django-tagging (http://code.google.com/p/
django-tagging/):
models.py:
from tagging.validators import isTag
name = models.CharField(validator_list=[isTag])
validators.py:
def isTag(field_data, all_data):
"""
Validates that ``field_data`` is a valid tag name.
"""
if not isinstance(field_data, unicode):
field_data = field_data.decode(settings.DEFAULT_CHARSET)
i like this way to define validator , but i t did not work for me.i
just want to know dose such code is still valid now?
On 9月10日, 下午5时36分, Nis J rgensen <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] skrev:> i used this: def isBlank(field,all_data): if
> field_data is None:
> > raise ValidattionError(u'Cannot be Blank.')
>
> > it not work for me.
>
> It seems you are being bitten by the behavior described thus in the
> documentation:
>
> """
> After a form has been submitted, Django validates each field in turn.
> First, if the field is required, Django checks that it is present and
> non-empty. Then, if that test passes /and the form submission contained
> data/ for that field, all the validators for that field are called in
> turn. The emphasized portion in the last sentence is important: if a
> form field is not submitted (because it contains no data - which is
> normal HTML behavior), the validators are not run against the field.
> ...
> If you would like your validator to run /always/, regardless of whether
> its attached field contains any data, set the always_test attribute on
> the validator function. For example:
>
> def my_custom_validator(field_data, all_data):
> # ...
> my_custom_validator.always_test = True
>
> """
>
> --
> Nis Jorgensen
> Handcrafting signatures since 1996
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---