diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-06-30 14:30:32 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-06-30 14:30:32 +0200 |
| commit | 596e15293c9f522a2b001d49a0c40005711682a6 (patch) | |
| tree | f0f9f6f43741cedd715caa78d17a2ca54761b07a /docs | |
| parent | 47da7b7a9aefce66fa2c54833b5ba308781fc95e (diff) | |
Fixed #11162 -- Mentioned ValidationError in custom model field docs
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/howto/custom-model-fields.txt | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/docs/howto/custom-model-fields.txt b/docs/howto/custom-model-fields.txt index 99c5904fe9..8b4c2303ab 100644 --- a/docs/howto/custom-model-fields.txt +++ b/docs/howto/custom-model-fields.txt @@ -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`_ |
