I have a django app with rest framework and I noticed that some DecimalField are serialized as string, others as numbers. Why? Here's my model:
class TestModel(models.Model):
quantity1 = models.DecimalField("quantity1", default=0.0, max_digits=10, decimal_places=3)
quantity2 = models.DecimalField("quantity2", default=0.0, max_digits=10, decimal_places=3)
quantity3 = models.DecimalField("quantity3", default=0.0, max_digits=10, decimal_places=3)
latitude = models.DecimalField(max_digits=9, decimal_places=6)
longitude = models.DecimalField(max_digits=9, decimal_places=6)
Here's the serialization
"quantity1": "1.000",
"quantity2": "1.000",
"quantity3": "1.000",
"latitude": 45.49907,
"longitude": 9.18749,
Here is the serialize class used:
class TestModelSerializer(serializers.ModelSerializer):
class Meta:
model = TestModel
fields = [
"id",
"quantity1",
"quantity2",
"quantity3",
"latitude",
"longitude"
]
I am aware of the problem of serialize floating point and their precision (see here), but why quantities are represented as string while lat/lon are numbers? They are both decimalFields...