[BangPypers] Django - Infinte Loop
arunvr at gmail.com
Fri Jul 11 12:55:05 CEST 2014
>From Django 1.7 onwards, the proper way to register signals will be inside
a ready function
in the app's configuration object. This is thanks to the App-loading
refactor done in the release.
In your case, as mentioned in the docs, create an myapp/apps.py with :
from django.apps import AppConfig
MyModel = self.get_model('MyModel')
Also add a line to myapp/__init__.py :
default_app_config = 'myapp.apps.MyAppConfig'
This would eliminate circular imports.
On Fri, Jul 11, 2014 at 12:37 PM, Anand Reddy Pandikunta <
anand21nanda at gmail.com> wrote:
> I have overrided model save.
> Moved couple of functions from models.py to tasks.py which lead to circular
> Instead of importing models at the beginning of file, I've imported them in
> the functions.
> Thank you @krace, @navin, @pradip :)
> On Thu, Jul 10, 2014 at 11:12 AM, Pradip Caulagi <ppc.lists at gmail.com>
> > On Tuesday 08 July 2014 01:13 PM, Anand Reddy Pandikunta wrote:
> >> Hi,
> >> *models.py*
> >> *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)*
> > Like others have noted, you should override model save. Another option
> > would be to use pre_save. Just set instance.status and don't call
> > instance.save?
> > _______________________________________________
> > BangPypers mailing list
> > BangPypers at python.org
> > https://mail.python.org/mailman/listinfo/bangpypers
> - Anand Reddy Pandikunta
> BangPypers mailing list
> BangPypers at python.org
More information about the BangPypers