This is my model:
class Stock_Total(models.Model):
purchases = models.ForeignKey(Purchase,on_delete=models.CASCADE,null=True,blank=True,related_name='purchasetotal')
stockitem = models.ForeignKey(Stockdata,on_delete=models.CASCADE,null=True,blank=True,related_name='purchasestock')
gst_rate = models.DecimalField(max_digits=4,decimal_places=2,default=5)
@receiver(pre_save, sender=Stock_Total)
def update_gst_rate(sender, instance, *args, **kwargs):
instance.gst_rate = instance.stockitem.gst_rate
@receiver(post_save, sender=Purchase)
def trigger_gst(sender, instance, *args, **kwargs):
instance.purchasetotal.save()
"Purchase" and "Stockdata" are other model which I have created...I just want to save the Stock_Total model whenever the Purchase model is saved i.e. when I click on save on Purchase model the Stock_Total model will automatically be updated along with the purchase model...
Do anyone have any idea?