开发者

signals do not work in a standalone script?

开发者 https://www.devze.com 2023-04-12 16:40 出处:网络
in my models.py: from django.db import models from django.dispatch import receiver class MyModel(models.Model):

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消