I have a model with the following:
regular_price = models.DecimalField(
verbose_name=("Regular price"),
help_text=("Price you which to sell the product"),
error_messages={
"name": {
"max_length": ("The price you want to sell the product"),
},
},
max_digits=10,
decimal_places=2, default=0
)
discount_price = models.DecimalField(
verbose_name=("Discount price"),
help_text=(
"The amount you want to remove from the actual price, leave to reduce nothing"),
error_messages={
"name": {
"max_length": ("you can leave or put the price you want to reduce."),
},
},
max_digits=10,
decimal_places=2, blank=True, null=True
Now I have a function that calculates the actual price:
def actual_price(self):
price = (self.regular_price)-(self.discount_price)
return price
when I call the function (actual_price) from the front end, I keep receiving the following error message:
unsupported operand type(s) for -: ‘decimal.Decimal’ and ‘NoneType’
My question is that what is the proper way to perform subtraction of decimals in django?