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

File django-model-choice-field-validation.diff, 963 bytes (added by Petr Marhoun <petr.marhoun@…>, 6 years ago)
  • django/forms/models.py

    # HG changeset patch
    # User Petr Marhoun <petr.marhoun@gmail.com>
    # Date 1262727798 -3600
    # Node ID 808774980dda1222ec10360e2fd53dc994402342
    # Parent  905311cd1716f58b994115cf5a782de20bf536c7
    [mq]: django-model-choice-field-validation.diff
    
    diff --git a/django/forms/models.py b/django/forms/models.py
    a b  
    875875
    876876    choices = property(_get_choices, ChoiceField._set_choices)
    877877
    878     def clean(self, value):
    879         Field.clean(self, value)
     878    def to_python(self, value):
    880879        if value in EMPTY_VALUES:
    881880            return None
    882881        try:
     
    886885            raise ValidationError(self.error_messages['invalid_choice'])
    887886        return value
    888887
     888    def validate(self, value):
     889        return Field.validate(self, value)
     890
    889891class ModelMultipleChoiceField(ModelChoiceField):
    890892    """A MultipleChoiceField whose choices are a model QuerySet."""
    891893    widget = SelectMultiple
Back to Top