Reputation: 17
I'm new with python and I create two models (Shoes and Order) I can add record by admin panel but I want each time that I add order record it's check weather the shoes are available or not! where should I put logic?
Upvotes: 0
Views: 128
Reputation: 886
There are a few options to do this:
A) On pre_save
signal. In case you want to do check before you store an object in DB:
@receiver(pre_save, sender=OrderRecord)
def handler_order_check(sender, instance, **kwargs):
...
B) On post_save
signal or in Molde.save
method, a check will be done after object is created:
@receiver(post_save, sender=OrderRecord)
def handler_order_check(sender, instance, **kwargs):
...
C) On admin form. In case you want to keep the check in admin side only, when objects created from f/e & shell will not have such check, related docs.
I would recommend using A, as it does the check every time you create (or update, depends on implementation) OrderRecord
.
Upvotes: 1