I have an existing model that I want to extend using multi-table inheritance. I need to create a child instance for each parent instance in the database, but I can't figure out how. I've scoured google and haven't come up with anything other than Ticket #7623[1]. Here are some of the things I've tried...
Let's adapt the Place / Restaurant example from the docs: class Place(models.Model): name = models.CharField(max_length=50) address = models.CharField(max_length=80) class Restaurant(Place): place = models.OneToOneField(Place, parent_link=True, related_name='restaurant') serves_hot_dogs = models.BooleanField() serves_pizza = models.BooleanField() I want to do the following, in essence: for place in Place.objects.all(): restaurant = Restaurant(**{ 'place': place, 'serves_hot_dogs': False, 'serves_pizza': True, }) restaurant.save() Of course, doing this tries to also create a new Place belonging to the new Restaurant, and throws an error because no values have been specified for the name and address fields. I've also tried: for place in Place.objects.all(): restaurant = Restaurant(**{ 'serves_hot_dogs': False, 'serves_pizza': True, }) place.restaurant = restaurant place.save() This, however, doesn't create any records in the restaurant table. Any suggestions? [1] http://code.djangoproject.com/ticket/7623 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.