Skip to content Skip to sidebar Skip to footer

Django: Store Common Fields In A Parent Model

I've got some models: class Place(models.Model): name = models.CharField(unique=True) class Bar(Place): drinks = models.ManyToManyField('Drink') class Restaurant(Place):

Solution 1:

Django's abstract base classes solve the problem of sharing common fields between models:

class Place(models.Model):
    name = models.CharField(unique=True)

    class Meta:
        abstract = True

Edit: Having said that, as Daniel mentioned in the comments, the solution you propose should work just fine. Here's more on Django's multi-table inheritance


Post a Comment for "Django: Store Common Fields In A Parent Model"