Как отнять процент скидки товара от суммы товара? вот код P.S(цена указана через Decimal)
class Product(models.Model):
name = models.CharField(max_length=40)
slug = models.SlugField(unique=True, blank=True)
price = models.DecimalField(max_digits=10, decimal_places=2, default=0)
discount = models.IntegerField(default=0)
stock = models.PositiveIntegerField(default=1)
category = models.ForeignKey(ProductCategory, blank=True, null=True, default=None)
short_description = models.TextField(max_length=220, blank=True, default=None)
description = models.TextField(max_length=500, blank=True, default=None)
is_active = models.BooleanField(default=True)
publish = models.DateField(auto_now=False, auto_now_add=True)
timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)
def __str__(self):
return "{0}:|:{1}".format(self.price, self.name)
class Meta:
ordering = ["-timestamp"]
verbose_name = 'Product'
verbose_name_plural = 'Products'
def get_absolute_url(self):
#return reverse("products:product_url", kwargs={"slug": self.slug})
return "/products/product/%s" %(self.slug)
def save(self, *args, **kwargs):
discount = self.discount
price = self.price
if discount > 0:
super(Product, self).save(*args, **kwargs)