diff --git a/django_any/models.py b/django_any/models.py index 7fd6f0a..0e89681 100644 --- a/django_any/models.py +++ b/django_any/models.py @@ -32,21 +32,23 @@ @any_field.decorator def any_field_blank(function): """ - Sometimes return empty value if field could be blank + Sometimes return empty value if field could be blank and + `settings.ALWAYS_FILL_BLANK_FIELDS` is `False` (default) """ def wrapper(field, **kwargs): # any_model(Entry, pub_date__isnull=True) if kwargs.get('isnull', False): return None - if field.blank and random.random() < 0.1: - if field.null: - return None - else: - try: - return field.to_python('') - except ValidationError as e: # bool, int, etc. - pass + if not getattr(settings, 'ALWAYS_FILL_BLANK_FIELDS', False): + if field.blank and random.random() < 0.1: + if field.null: + return None + else: + try: + return field.to_python('') + except ValidationError as e: # bool, int, etc. + pass return function(field, **kwargs) return wrapper