Monday, October 22, 2012

Re: Raising a ValidationError in a custom field's to_python method?

On lun., oct. 22 2012, Nicolas Dandrimont wrote:
> #------8<----{ fields.py }---->8------#
> import netaddr
>
> from django.core.exceptions import ValidationError
> from django.db import models
>
> [...]
> def to_python(self, value):
> if not isinstance(value, netaddr.EUI):
> try:
> value = netaddr.EUI(value)
> except netaddr.AddrFormatError as e:
> raise FormValidationError("Adresse MAC invalide: %s" % repr(value))
^^^^^^^^^^^^^^^^^^^
Oh, well, this is a typo and should read ValidationError...

Cheers,
--
Nicolas Dandrimont

BOFH excuse #62:
need to wrap system in aluminum foil to fix problem

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment