Skip to content

Commit

Permalink
Merge pull request coagulant#51 from hovel/fix_any_field_blank
Browse files Browse the repository at this point in the history
fix coagulant#49 any_field_blank shouldn't return None if field can't be None
  • Loading branch information
GeyseR committed Oct 11, 2016
2 parents 5805ecd + 0e0507e commit 7ec5098
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions django_any/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,22 @@
@any_field.decorator
def any_field_blank(function):
"""
Sometimes return None if field could be blank
Sometimes return empty value if field could be blank
"""
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:
return None
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

Expand Down

0 comments on commit 7ec5098

Please sign in to comment.