Hello I'm trying to make on update trigger in Django Model.个
Model.py个
class Item(models.Model):
status_type = (
('a','Active'),
('d','Deactive')
)
code = models.CharField(max_length=100, null=True, blank=True, unique=True)
name = models.CharField(max_length=100)
price = models.DecimalField(max_digits=10, decimal_places=2)
gsts = models.ForeignKey(Gst, on_delete=models.CASCADE)
sgst = models.DecimalField(max_digits=10, decimal_places=2,null=True,blank=True)
cgst = models.DecimalField(max_digits=10, decimal_places=2,null=True,blank=True)
net_amount = models.DecimalField(max_digits=10, decimal_places=2,null=True,blank=True)
status = models.CharField(max_length=1, choices=status_type, default = 'a')
create_at = models.DateField(auto_now_add=True)
update_at = models.DateField(auto_now=True)
create_by = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return self.name
def ItemGenerator(sender, instance, created, *args, **kwargs):
if created:
id = instance
query = Item.objects.get(id = int(id.id))
#gst calculation
gst_cal = query.price * query.gsts.gst/100
#net amount calculation
net_amounts = query.price + gst_cal
#item number generate
temp_count = Item.objects.all().count()
no = str('ITEM') + '/' +str(temp_count)
query = Item.objects.filter(id = id.id).update(code = str(no), cgst = round(gst_cal/2), sgst=round(gst_cal/2), net_amount = round(net_amounts))
When I'm insert to the data post_save signal is call and my price and gst calculation save into data base but problem is that when I'm update the record post_save signal is not working个