mirror of
https://github.com/django/django.git
synced 2024-12-23 09:36:06 +00:00
Fixed #11162 -- Mentioned ValidationError in custom model field docs
This commit is contained in:
parent
47da7b7a9a
commit
596e15293c
@ -434,10 +434,14 @@ database, so we need to be able to process strings and ``Hand`` instances in
|
||||
p1 = re.compile('.{26}')
|
||||
p2 = re.compile('..')
|
||||
args = [p2.findall(x) for x in p1.findall(value)]
|
||||
if len(args) != 4:
|
||||
raise ValidationError("Invalid input for a Hand instance")
|
||||
return Hand(*args)
|
||||
|
||||
Notice that we always return a ``Hand`` instance from this method. That's the
|
||||
Python object type we want to store in the model's attribute.
|
||||
Python object type we want to store in the model's attribute. If anything is
|
||||
going wrong during value conversion, you should return a
|
||||
:exc:`~django.core.exceptions.ValidationError` exception.
|
||||
|
||||
**Remember:** If your custom field needs the :meth:`to_python` method to be
|
||||
called when it is created, you should be using `The SubfieldBase metaclass`_
|
||||
|
Loading…
Reference in New Issue
Block a user