Django model inheritance: create sub-instance of existing instance (downcast)?

前端 未结 7 1945
野的像风
野的像风 2020-11-29 01:52

I\'m trying to integrate a 3rd party Django app that made the unfortunate decision to inherit from django.contrib.auth.models.User, which is a big no-no for plu

7条回答
  •  臣服心动
    2020-11-29 02:21

    This should work:

    extended_user = ExtendedUser(user_ptr_id=auth_user.pk)
    extended_user.__dict__.update(auth_user.__dict__)
    extended_user.save()
    

    Here you're basically just copying over the values from the auth_user version into the extended_user one, and re-saving it. Not very elegant, but it works.

提交回复
热议问题