mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-05-09 18:33:42 +03:00
Fix order for applying min_value to fields
This commit is contained in:
parent
0c81d04170
commit
025c40e7d5
|
@ -739,15 +739,16 @@ class ModelSerializer(Serializer):
|
||||||
if issubclass(model_field.__class__, models.TextField):
|
if issubclass(model_field.__class__, models.TextField):
|
||||||
kwargs['widget'] = widgets.Textarea
|
kwargs['widget'] = widgets.Textarea
|
||||||
|
|
||||||
if issubclass(model_field.__class__, models.PositiveIntegerField) or\
|
|
||||||
issubclass(model_field.__class__, models.PositiveSmallIntegerField):
|
|
||||||
kwargs['min_value'] = 0
|
|
||||||
|
|
||||||
# TODO: TypedChoiceField?
|
# TODO: TypedChoiceField?
|
||||||
if model_field.flatchoices: # This ModelField contains choices
|
if model_field.flatchoices: # This ModelField contains choices
|
||||||
kwargs['choices'] = model_field.flatchoices
|
kwargs['choices'] = model_field.flatchoices
|
||||||
return ChoiceField(**kwargs)
|
return ChoiceField(**kwargs)
|
||||||
|
|
||||||
|
# put this below the ChoiceField because min_value isn't a valid initializer
|
||||||
|
if issubclass(model_field.__class__, models.PositiveIntegerField) or\
|
||||||
|
issubclass(model_field.__class__, models.PositiveSmallIntegerField):
|
||||||
|
kwargs['min_value'] = 0
|
||||||
|
|
||||||
attribute_dict = {
|
attribute_dict = {
|
||||||
models.CharField: ['max_length'],
|
models.CharField: ['max_length'],
|
||||||
models.CommaSeparatedIntegerField: ['max_length'],
|
models.CommaSeparatedIntegerField: ['max_length'],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user