How do I prevent fixtures from conflicting with django post_save signal code?

前端 未结 4 1796
清酒与你
清酒与你 2020-11-29 20:56

In my application, I want to create entries in certain tables when a new user signs up. For instance, I want to create a userprofile which will then reference their company

4条回答
  •  囚心锁ツ
    2020-11-29 21:48

    I think I figured out a way to do this. There is a 'raw' parameter in the kwargs passed in along with signals so I can replace my test above with this one:

    if (kwargs.get('created', True) and not kwargs.get('raw', False)):
    

    Raw is used when loaddata is running. This seems to do the trick.

    It is mentioned here: http://code.djangoproject.com/ticket/13299

    Would be nice if this was documented: http://docs.djangoproject.com/en/1.2/ref/signals/#django.db.models.signals.post_save

提交回复
热议问题