Skip to content

Commit

Permalink
Merge pull request coagulant#52 from hovel/fix_field_choices_attibute
Browse files Browse the repository at this point in the history
Do not call random.choice for fields which have no valid choices
  • Loading branch information
GeyseR committed Oct 31, 2016
2 parents 7ec5098 + f9fca0f commit 324c8ad
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion django_any/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def field_choices_attibute(function):
"""
def _wrapper(field, **kwargs):
if hasattr(field.widget, 'choices'):
return random.choice(list(valid_choices(field.widget.choices)))
valid_only = list(valid_choices(field.widget.choices))
if valid_only:
return random.choice(valid_only)
return function(field, **kwargs)

return _wrapper
Expand Down

0 comments on commit 324c8ad

Please sign in to comment.