Django model inheritance: Create a subclass using existing super class

后端 未结 2 1381
时光取名叫无心
时光取名叫无心 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:48

    Multi-table inheritance is just OneToOneField relation between Place and Restaurant.

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

提交回复
热议问题