Code

Ticket #12510: django-model-choice-field-validation.diff

File django-model-choice-field-validation.diff, 963 bytes (added by Petr Marhoun <petr.marhoun@…>, 4 years ago)
Line 
1# HG changeset patch
2# User Petr Marhoun <petr.marhoun@gmail.com>
3# Date 1262727798 -3600
4# Node ID 808774980dda1222ec10360e2fd53dc994402342
5# Parent  905311cd1716f58b994115cf5a782de20bf536c7
6[mq]: django-model-choice-field-validation.diff
7
8diff --git a/django/forms/models.py b/django/forms/models.py
9--- a/django/forms/models.py
10+++ b/django/forms/models.py
11@@ -875,8 +875,7 @@
12 
13     choices = property(_get_choices, ChoiceField._set_choices)
14 
15-    def clean(self, value):
16-        Field.clean(self, value)
17+    def to_python(self, value):
18         if value in EMPTY_VALUES:
19             return None
20         try:
21@@ -886,6 +885,9 @@
22             raise ValidationError(self.error_messages['invalid_choice'])
23         return value
24 
25+    def validate(self, value):
26+        return Field.validate(self, value)
27+
28 class ModelMultipleChoiceField(ModelChoiceField):
29     """A MultipleChoiceField whose choices are a model QuerySet."""
30     widget = SelectMultiple