Django admin form fields for a models.DecimalField with value 0 or 0.0 show "0E-8"
|Reported by:||nebstrebor||Owned by:||antofik|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
We use django admin as a client-facing backend, so we need to make it user friendly. I have a model with a bunch of DecimalFields representing nutritional data.
The fields all look like this:
g_carbs = DecimalField(max_digits=13, decimal_places = 8, null=True, blank=True)
If the field is left blank, or if a non-zero value is provided, the admin form looks and works great. For example, for a non-blank, non-zero value like 10.5, it displays something like 10.50000000, which is fine.
The problem is that for any 0 values, the form field displays 0E-8 which, although technically correct, is not going to cut it for clients, who are not scientists or engineers for the most part and are unfamiliar with E notation. We're using DecimalFields rather than FloatFields to avoid this type of notation.
I am not using a custom ModelForm or any custom admin tricks. Its just what gets auto-rendered by django admin for that model.
Change History (6)
comment:1 Changed 4 years ago by mrj
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Design decision needed
comment:3 Changed 3 years ago by aaugustin
- Triage Stage changed from Design decision needed to Accepted
comment:4 Changed 3 years ago by antofik
- Owner changed from nobody to antofik
- Status changed from new to assigned