Django 1.5 custom user model - signals limitation

前端 未结 3 555
情歌与酒
情歌与酒 2021-01-27 11:00

It\'s written in the doc that:

Another limitation of custom User models is that you can’t use django.contrib.auth.get_user_model() as the sender or target

3条回答
  •  长情又很酷
    2021-01-27 11:30

    You can simply use the setting AUTH_USER_MODEL or any model as a string, e.g. 'users.MyCustomUser':

    def user_post_save_handler(**kwargs):
        # do something
    post_save.connect(user_post_save_handler, sender=settings.AUTH_USER_MODEL)
    

提交回复
热议问题