class MySerializer(serializers.Serializer):
contract = fields.ChoiceField(choices=(
('no', 'no'),
('yes', 'yes'),
))
So here my input can be one of the following. no, No,Yes,yes
for these do I need to add 2 more entry for Capital one?
contract = fields.ChoiceField(choices=(
('no', 'no'),
('yes', 'yes'),
('No', 'no'),
('Yes', 'yes'),
))
or is there any way by which we can ignore the case?
Set to false if this field is not required to be present during deserialization. Setting this to False also allows the object attribute or dictionary key to be omitted from output when serializing the instance. If the key is not present it will simply not be included in the output representation. Defaults to True .
The ModelSerializer class is the same as a regular Serializer class, except that: It will automatically generate a set of fields for you, based on the model. It will automatically generate validators for the serializer, such as unique_together validators.
is_valid perform validation of input data and confirm that this data contain all required fields and all fields have correct types. If validation process succeded is_valid set validated_data dictionary which is used for creation or updating data in DB.
http://www.django-rest-framework.org/api-guide/fields/#choicefield
If you want to leave it to user, you might have to think of more options like "yes", "Yes", "YES" instead of just "yes, "Yes"
I prefer you convert them to lower and set it on the field by using .lower(), so that you will always get lowercase letters as input
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With