[BangPypers] Django - Infinte Loop
kracethekingmaker at gmail.com
Tue Jul 8 09:57:09 CEST 2014
I would save *don't* use Django signal. Signals are hard to test and don't
know when they will be executed.
- If post_save function does some work like updating external service which
can take data, use rq or celery.
- You can override django save.
def save(self, **kwargs)
# set all attributes
# call super class save
# call function here - blocking call.
On Tue, Jul 8, 2014 at 1:13 PM, Anand Reddy Pandikunta <
anand21nanda at gmail.com> wrote:
> *def my_func(sender, instance, created, **kwargs):*
> * # do something*
> * instance.status = 'task completed'*
> * instance.save()*
> *class MyModel(models.Model):*
> * status = models.CharField(max_length=100, blank=True)*
> * # some code*
> *signals.post_save.connect(my_func, sender=MyModel)*
> I am using post_save signal to connect to a function.
> If a new instance of model is saved, post_save signal connects to my_func.
> Once the function is executed, I am updating status of the model.
> This is again sending post_save signal which is leading to infinite loop.
> I want to execute my_func only once and update status many times.
> Does any one know how to do this?
> - Anand Reddy Pandikunta
> BangPypers mailing list
> BangPypers at python.org
*Thanks & Regardskracekumar"Talk is cheap, show me the code" -- Linus
More information about the BangPypers