我有两个像这样的 django 模型:
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
class Restaurant(Place):
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()
我之前创建了一个Place
实例,如下所示:
sixth_ave_street_vendor = Place(name='Bobby Hotdogs', address='6th Ave')
sixth_ave_street_vendor.save()
现在,鲍比已经将他的街头小贩升级为餐厅。我怎么能在我的代码中做到这一点?!为什么此代码不起作用:
sixth_ave_restaurant = Restaurant(place=sixth_ave_street_vendor,
serves_hot_dogs=True,
serves_pizza=True)
sixth_ave_restaurant.save()