signals do not work in a standalone script?
in my models.py
:
from django.db import models
from django.dispatch import receiver
class MyModel(models.Model):
slug = models.SlugField()
@receiver(models.signals.pre_save, sender=MyModel)
def on_pre_save(sender, **kwargs):
print 'on_pre_save'
when I create a model instance from a command line when running manage.py shell
. The signal gets dispatched and I see the output.
But when I use my model in a standalone script, the si开发者_如何学运维gnal does not seem to get dispatched because I see no output. why?
My script's initialization logic was outdated. After I converted this script into a manage.py custom command, signals started working.
精彩评论