0

Is it possible to store in my models decimal fields with four decimal places but to show only two in Django admin forms.

class MyModel(models.Model):
    purchase_price_gross = models.DecimalField(
        'Purchase price (gross)', validators=[MinValueValidator(0.0)], 
    max_digits=19, decimal_places=4)

Now in the Admin form the field is showing with 4 decimal places. But how can I restrict the forms to show only two places?

user3142459
  • 630
  • 5
  • 18

1 Answers1

1

What you want is floatformat: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#floatformat

    {{ value|floatformat }}

So you could edit the admin view to use that, which is covered here:

https://stackoverflow.com/a/29997719/1650488

Just in terms of Django best practices though, it seems like you might be pushing the admin view further than you maybe should, and you should build a custom view?

Ryan
  • 1,032
  • 1
  • 10
  • 23