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

前端 未结 7 1941
野的像风
野的像风 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:32

    If you don't like __dict__.update solution you can do this:

    for field in parent_obj._meta.fields
        setattr(child_obj, field.attname, getattr(parent_obj, field.attname))
    

提交回复
热议问题