Is there any way in the Django Rest framework serializer to ignore the case in the select box?

class MySerializer(serializers.Serializer):
  contract = fields.ChoiceField(choices=(
    ('no', 'no'),
    ('yes', 'yes'),
  ))

So here my input may be one of the following. no no yes yes

for this I need to add 2 more entries for Capital one?

contract = fields.ChoiceField(choices=(
    ('no', 'no'),
    ('yes', 'yes'),
    ('No', 'no'),
    ('Yes', 'yes'),

  ))

or is there a way we can ignore the case?

+4
source share
1 answer

http://www.django-rest-framework.org/api-guide/fields/#choicefield

If you want to leave it to the user, you may need more options, such as yes, yes, YES instead of yes, yes

, .lower(),

0

Source: https://habr.com/ru/post/1610557/


All Articles