Django==2.2.6
djangorestframework==3.10.3
Models.py
VAT_CHOICES = [(Decimal('0.00'), '0%'), (Decimal('6.00'), '6%'), (Decimal('12.00'), '12%'), (Decimal('25.00'), '25%')]
class Service(models.Model):
vat = models.DecimalField(verbose_name=_('vat'), decimal_places=2, max_digits=10, choices=VAT_CHOICES)
serializers.py
class ServiceSerializer(serializers.ModelSerializer):
vat = serializers.DecimalField(decimal_places=2, max_digits=10, coerce_to_string=True)
If I do this then the value of vat in response is in srting as expected but the choices validation does not implied then.
Now I can create a service with vat="5.00" which should not be possible because there is a choice list in the model.
How can I have the string representation of the decimal field vat but keep the choices validation?