Ticket #19989: 19989-1.diff

File 19989-1.diff, 1.8 KB (added by Claude Paroz, 11 years ago)
  • django/db/models/fields/__init__.py

    diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
    index f8ec205..f9f913b 100644
    a b class Field(object):  
    5757    # Designates whether empty strings fundamentally are allowed at the
    5858    # database level.
    5959    empty_strings_allowed = True
     60    empty_values = list(validators.EMPTY_VALUES)
    6061
    6162    # These track each time a Field instance is created. Used to retain order.
    6263    # The auto_creation_counter is used for fields that Django implicitly
    class Field(object):  
    157158        return value
    158159
    159160    def run_validators(self, value):
    160         if value in validators.EMPTY_VALUES:
     161        if value in self.empty_values:
    161162            return
    162163
    163164        errors = []
    class Field(object):  
    184185            # Skip validation for non-editable fields.
    185186            return
    186187
    187         if self._choices and value not in validators.EMPTY_VALUES:
     188        if self._choices and value not in self.empty_values:
    188189            for option_key, option_value in self.choices:
    189190                if isinstance(option_value, (list, tuple)):
    190191                    # This is an optgroup, so look inside the group for
    class Field(object):  
    200201        if value is None and not self.null:
    201202            raise exceptions.ValidationError(self.error_messages['null'])
    202203
    203         if not self.blank and value in validators.EMPTY_VALUES:
     204        if not self.blank and value in self.empty_values:
    204205            raise exceptions.ValidationError(self.error_messages['blank'])
    205206
    206207    def clean(self, value, model_instance):
    class URLField(CharField):  
    12951296
    12961297class BinaryField(Field):
    12971298    description = _("Raw binary data")
     1299    empty_values = [None, b'']
    12981300
    12991301    def __init__(self, *args, **kwargs):
    13001302        kwargs['editable'] = False
Back to Top