开发者

How to recognize that Django fixtures loading is ongoing?

I have delusions that I've seen it in some piece of code and it's so开发者_高级运维me variable's state. Example usage would be in signal handlers.


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.


(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.
        ...
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜