As it exists now, multi-table inheritance does not allow for the
creation of a child model instance that inherits from an existing parent
model instance. For example:
Parent Class-
class Place(models.Model): name = models.CharField(max_length=50) address = models.TextField(max_length=150)
Child Classes-
class Restaurant(Place): place = models.OneToOneField(Place, parent_link=True) cuisine = models.CharField(max_length=75) rating = models.IntegerField() class Bar(Place): parent = models.OneToOneField(Place, parent_link=True) happy_hour = models.BooleanField() beers_on_tap = models.ManyToManyField("Beers", null=True, blank=True)
Sample Use-case-
When the system is first deployed, a restaurant instance is created.
Later, the restaurant adds a bar to increase revenue, and we now want to
create a Bar model instance for the parent Place for the restaurant. I
would propose the following interface for doing so:
parentPlace = Restaurant.objects.get(name__iexact="Bob's Place").parent barInstance = Bar(parent=parentPlace, happy_hour=True)However, if you attempt to create an instance in this manner now, you receive a DatabaseIntegrityError, saying that a Place object with that id already exists.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d4273754-670e-4697-b0b4-9626c42a5aaf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
parent = Restaurant.objects.get(name__iexact="Bob's Place").parent
bar = Bar(parent=parent, happy_hour=True)
bar.save_base(raw=True)