如何识别 Django 设备正在加载?

发布于 2024-09-30 02:34:55 字数 50 浏览 8 评论 0原文

我有一种错觉,我在一段代码中看到了它,它是某个变量的状态。示例用法是在信号处理程序中。

I have delusions that I've seen it in some piece of code and it's some variable's state. Example usage would be in signal handlers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜扑 2024-10-07 02:34:55

我还没有检查过,但是从这个讨论中, http://code.djangoproject.com/ticket /8399 看来loaddata发出了post_save信号。

I haven't checked it out yet, but from this discussion, http://code.djangoproject.com/ticket/8399 it seems that loaddata sends out post_save signals.

给不了的爱 2024-10-07 02:34:55

(8年后)偶然发现了自己的问题,示例如下(在>=1.11中测试):

from django.db.models.signals import pre_save
from django.dispatch import receiver

@receiver(pre_save) # `post_save` also works
def callback_on_loaddata(sender, **kwargs):
    # 'raw' indicates that loaddata cmd was issued
    if kwargs.get('created', True) and kwargs.get('raw', False):
        # mark on-going loaddata, call kwargs.get('instance').clean() etc.
        ...

(8 years later) stumbled upon own question, and the example would be (tested in >=1.11):

from django.db.models.signals import pre_save
from django.dispatch import receiver

@receiver(pre_save) # `post_save` also works
def callback_on_loaddata(sender, **kwargs):
    # 'raw' indicates that loaddata cmd was issued
    if kwargs.get('created', True) and kwargs.get('raw', False):
        # mark on-going loaddata, call kwargs.get('instance').clean() etc.
        ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文