Django model inheritance: Create a subclass using existing super class

后端 未结 2 1401
时光取名叫无心
时光取名叫无心 2020-12-08 00:47

I\'m using multi-table-inheritance, and want to know how to create an inherited type from an instance of the superclass.

Using the example given in the documentation

2条回答
  •  佛祖请我去吃肉
    2020-12-08 01:41

    place = Place.objects.get(id=1)
    
    # Create a restaurant using existing Place
    place.__class__ = Restaurant
    place.save()
    restaurant = place
    

提交回复
热议问题