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

前端 未结 7 1946
野的像风
野的像风 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条回答
  •  猫巷女王i
    2020-11-29 02:17

    I found this answer by asking on django-user mailing list:

    https://groups.google.com/d/msg/django-users/02t83cuEbeg/JnPkriW-omQJ

    This isn't part of the public API but you could rely on how Django loads fixture internally.

    parent = Restaurant.objects.get(name__iexact="Bob's Place").parent
    bar = Bar(parent=parent, happy_hour=True)
    bar.save_base(raw=True)
    

    Keep in mind that this could break with any new version of Django.

提交回复
热议问题