mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-12-04 07:24:03 +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.CommaSeparatedIntegerField: CharField,
|
||||||
models.BooleanField: BooleanField,
|
models.BooleanField: BooleanField,
|
||||||
}
|
}
|
||||||
try:
|
|
||||||
ret = field_mapping[model_field.__class__]()
|
if model_field.flatchoices: # This ModelField contains choices
|
||||||
except KeyError:
|
ret = ChoiceField(model_field.flatchoices)
|
||||||
ret = ModelField(model_field=model_field)
|
else:
|
||||||
|
try:
|
||||||
|
ret = field_mapping[model_field.__class__]()
|
||||||
|
except KeyError:
|
||||||
|
ret = ModelField(model_field=model_field)
|
||||||
|
|
||||||
if model_field.default is not None:
|
if model_field.default is not None:
|
||||||
ret.required = False
|
ret.required = False
|
||||||
|
|
Loading…
Reference in New Issue
Block a user