Show API choice field metadata more correctly for null vs ''

This commit is contained in:
Jeff Bradberry 2020-03-05 16:45:38 -05:00
parent 66c98ca9bc
commit d849e81891

View File

@ -101,8 +101,10 @@ class Metadata(metadata.SimpleMetadata):
(choice_value, choice_name) for choice_value, choice_name in field.choices.items()
]
if not any(choice in ('', None) for choice, _ in choices):
if field.allow_blank or (field.allow_null and not isinstance(field, ChoiceNullField)):
if field.allow_blank:
choices = [("", "---------")] + choices
if field.allow_null and not isinstance(field, ChoiceNullField):
choices = [(None, "---------")] + choices
field_info['choices'] = choices
# Indicate if a field is write-only.