Answer the question
In order to leave comments, you need to log in
How to call a function instead of an attribute in Django?
There is a model:
class Product(models.Model):
price = models.FloatField('Цена')
discount = models.IntegerField('Скидка')
Answer the question
In order to leave comments, you need to log in
# https://docs.python.org/3/library/decimal.html
from decimal import Decimal
class Product(models.Model):
price = models.DecimalField('Цена')
# подумай, почему никто никогда не использует флоат для денег
discount = models.IntegerField('Скидка')
def get_price_with_discount(self):
return self.price * Decimal(self.discount)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question