Exemplo n.º 1
0
    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = gen_slug(self.product_name)

        if self.product_discount >= 1: # burda error var ki, nonetype ile int arasi >= emeliyyati aparaila bilmez
            change = float(self.product_price) * float(self.product_discount) / 100
            self.product_discount_price = float(self.product_price) - change
        super().save(*args, **kwargs)
Exemplo n.º 2
0
def upload_product_file_loc(instance, filename):
    if instance.__class__ == ProductFile:
        slug = instance.product.slug
    else:
        slug = instance.slug
    _id = instance.id  # print edende birce id gelir, _ isaresini qoymanin menasi tam olaraq nedirki?
    print(_id)
    if _id is None:  # None olmadigi hal var olan obyekti edit etme hali ucundur?
        Klass = instance.__class__
        qs = Klass.objects.all().order_by('-pk')
        print(qs)
        if qs.exists():
            _id = qs.first().id + 1
        else:
            _id = 0
    if not slug:
        slug = gen_slug(instance.product)
    location = "product/{slug}/{id}/".format(slug=slug, id=_id)
    return location + filename
Exemplo n.º 3
0
 def save(self, *args, **kwargs):
     if not self.subcat_slug:
         self.subcat_slug = gen_slug(self.name)
     super().save(*args, **kwargs)