mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-12-03 23:14:07 +03:00
ModelSerializer.get_field() now returns a ChoiceField if the model has choices.
This commit is contained in:
parent
d1e05ea8d4
commit
91ea57bf98
|
@ -391,10 +391,14 @@ class ModelSerializer(Serializer):
|
|||
models.CommaSeparatedIntegerField: CharField,
|
||||
models.BooleanField: BooleanField,
|
||||
}
|
||||
try:
|
||||
ret = field_mapping[model_field.__class__]()
|
||||
except KeyError:
|
||||
ret = ModelField(model_field=model_field)
|
||||
|
||||
if model_field.flatchoices: # This ModelField contains choices
|
||||
ret = ChoiceField(model_field.flatchoices)
|
||||
else:
|
||||
try:
|
||||
ret = field_mapping[model_field.__class__]()
|
||||
except KeyError:
|
||||
ret = ModelField(model_field=model_field)
|
||||
|
||||
if model_field.default is not None:
|
||||
ret.required = False
|
||||
|
|
Loading…
Reference in New Issue
Block a user