I have the following pre_save signal in my models:
@receiver(pre_save, sender=Purchase)
def user_created_purchase_cgst(sender,instance,*args,**kwargs):
c = Journal.objects.filter(user=instance.user, company=instance.company).count() + 1
if instance.cgst_alltotal != None and instance.cgst_alltotal != 0:
Journal.objects.update_or_create(
user=instance.user,
company=instance.company,
by=ledger1.objects.filter(user=instance.user,company=instance.company,name__icontains='CGST').first(),
to=instance.party_ac,
defaults={
'counter' : c,
'date': instance.date,
'voucher_id' : instance.id,
'voucher_type' : "Journal",
'debit': instance.cgst_alltotal,
'credit': instance.cgst_alltotal}
)
I want to create another signal similar to the above that when the sender is deleted then the sender instance will also get deleted.
i.e when a Purchase
object is deleted then the corresponding Journal
object which is created by the pre_save signal will get deleted.
Any idea anyone how to perform this?
Thank you