I need to trigger any changes of some models. My models are: Brand, Product, Package. Package has fk to Product and Product has fk to Brand. So when some instances of these models are changed or created or deleted, I need to send signal. Can I implement it with post_save signal? I thought that if I write post_save signal for lower model: Package, then any changes with Brand or Product will be triggered. But it's not
            Asked
            
        
        
            Active
            
        
            Viewed 975 times
        
    1
            
            
         
    
    
        Andrew
        
- 423
- 1
- 6
- 16
- 
                    `post_save` is associated to a `save` method of a `Model`. So it will be executed only when that specific `save` method is triggered. – Gocht May 21 '15 at 20:26
- 
                    you have to write post_save signal for each of your model – Rizwan Mumtaz May 21 '15 at 20:30
1 Answers
0
            
            
        Why your signals are not triggered? Django's post_save is triggered in the end of model's save() method (docs). When you are updating your Package, Product still contains only a key to the Package model. So Product is not calling save().
What you can do:
- Create several post_savesignals.
- Override models' save()method.
To bind several post_save signals you simply do:
post_save.connect(do_package_stuff, Package, weak=False, dispatch_uid='package_post_save')
post_save.connect(do_product_stuff, Product, weak=False, dispatch_uid='product_post_save')
post_save.connect(do_brand_stuff, Brand, weak=False, dispatch_uid='brand_post_save')
Overriding save() is easier (and I can say more recommeneded). You can see this question if you are instrested in what is better.
 
    