I'm implementing some REST API in DRF with ModelViewSet
and ModelSerializer
. All my APIs use the JSON format and some of my models use ChoiceField field, like that:
MyModel(models.Model):
KEY1 = 'Key1'
KEY2 = 'Key2'
ATTRIBUTE_CHOICES = (
(KEY1, 'Label 1'),
(KEY2, 'Label 2'))
attribute = models.CharField(max_length=4,
choices=ATTRIBUTE_CHOICES, default=KEY1)
My problem is that by default DRF always returns (and accept) the key of these choices for JSON messages (see here), but I would like to use the label instead, because I think it's more consistent and clear to unterstand for who will use those APIs. Any suggestion?