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

前端 未结 4 1794
清酒与你
清酒与你 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:29

    Simple solution, add this to the beginning of your post_save function:

    if kwargs.get('raw', False):
        return False
    

    This will cause this function to exit when loading a fixture.

    See: https://docs.djangoproject.com/en/dev/ref/signals/#post-save

提交回复
热议问题