Django post_save signal not working properly

Viewed 29

In my models.py file, I have a class named OrderPayment, now whenever I create a new object of OrderPayment, I want to also create a Transaction object. Am trying to do this with post_save signal but it not working. Below is how the code looks

@receiver(post_save, sender=OrderPayment)
def orderpayment_setup(sender, instance, **kwargs):
    print(instance.order.dispatch_rider.company)
    print(instance)
    wt = Transaction.objects.create(
        wallet=Wallet.objects.get(user=instance.order.dispatch_rider.company),
        amount=instance.amount,
        description="Dispatch Order",
        status='success',
        transaction_type='deposit'
    )
    print(wt)

The orderpayment_setup function gets triggered but the Transaction object is not created. I also sees the first two print statement but I don't see the last one.

I don't know what I'm not doing right

0 Answers
Related