models.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:django-codenerix-products 作者: centrologic 项目源码 文件源码
def save(self, *args, **kwargs):
        with transaction.atomic():
            if self.default:
                TypeTax.objects.exclude(pk=self.pk).update(default=False)
            else:
                if not TypeTax.objects.exclude(pk=self.pk).filter(default=True).exists():
                    self.default = True

        if self.pk:
            obj = TypeTax.objects.get(pk=self.pk)
            if obj.tax != self.tax:
                result = super(TypeTax, self).save(*args, **kwargs)
                for product in self.products.all():
                    for pf in product.products_final.all():
                        pf.recalculate()
            else:
                result = super(TypeTax, self).save(*args, **kwargs)
        else:
            result = super(TypeTax, self).save(*args, **kwargs)
        return result


# atributos
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号