[Django]-How can I create an inherited django model instance from an existing base model instance?

5👍

Here is my workaround:

sixth_ave_restaurant = Restaurant(place_ptr=sixth_ave_street_vendor,
                                  serves_hot_dogs=True,
                                  serves_pizza=True)
sixth_ave_restaurant.save_base(raw=True)

And if you want to do something else with sixth_ave_restaurant, you should get it again, because its id is not assigned yet, as it gets assigned after normal save():

sixth_ave_restaurant = Restaurant.objects.get(id=sixth_ave_street_vendor.id)

3👍

You should use place_ptr instead of place.

restaurant = Restaurant.objects.create(place_ptr=sixth_ave_street_vendor,
                                       serves_hot_dogs=True, serves_pizza=True)

Leave a comment