Спасибо, но это не совсем то, что нужно.
С таким подходом
If you'd like to actually ensure that your model always gets saved
with only two decimal places, rather than just changing the
presentation of the model in a template, a custom save method on your
model will work great. The example model below shows how.
class MyDataModel(models.Model):
my_float = models.FloatField()
def save(self, *args, **kwargs):
self.my_float = round(self.my_float, 2)
super(MyDataModel, self).save(*args, **kwargs)
Now every time you save your model you will guarantee that the field will only be
populated with a float of two decimal places. This can be generalized
to rounding to any number of decimal places.
данные будут записываться в БД с точностью 2 знаки после точки, а мне этого не нужно, я хочу чтобы данные сохранялись с точностью по умолчанию (float двойной точности), а отображались в форме (форма редактирования объекта) - с 2 знаками после точки.
Updated 28 May 2020, 23:49 by -Igor-.