Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7085729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:27:38+00:00 2026-05-28T07:27:38+00:00

I have this use case scenario: there are places which are either playgrounds, restaurants,

  • 0

I have this use case scenario:
there are places which are either playgrounds, restaurants, theatres, pubs.
the same place can have playgrounds, restaurants, theatres etc.
there are couple of ways of implementing it:

  1. use foreign keys

    class Place(models.Model):
        name = models.CharField(max_length=50)
    
    class PlayGrounds(models.Model)
        field1 = models.CharField(max_length=50)
        place = models.ForeignKey(Place)
    
  2. multitable inheritance

    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()
    
  3. use abstract class

    class Place(models.Model):
        name = models.CharField(max_length=50)
    
    class PlayGrounds(Place)
        field1 = models.CharField(max_length=50)
        place = models.ForeignKey(Place)
        class Meta:
            abstract = True
    
  4. use proxy models

    class Place(models.Model):
        name = models.CharField(max_length=50)
    
    class PlayGrounds(Place)
        field1 = models.CharField(max_length=50)
        place = models.ForeignKey(Place)
        class Meta:
            proxy = True
    

What are the pros and cons of using each approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:27:39+00:00Added an answer on May 28, 2026 at 7:27 am

    The first one is essentially model inheritance, because that’s what Django’s implementation of MTI uses (except it’s a OneToOneField instead of a ForeignKey, but that’s merely a ForeignKey that’s unique).

    Anytime you have an is-a relationship (i.e., a Restaurant is a Place), you’re dealing with inheritance, so using one of Django’s model inheritance methodologies is the way to go. Each, however, has its pros and cons:

    Abstract Models

    Abstract models are useful when you just want to off-load repetitive fields and/or methods. They’re best used as mixins, more than true “parents”. For example, all of these models will have an address, so creating an abstract Address model and having each inherit from that might be a useful thing. But, a Restaurant is not an Address, per se, so this is not a true parent-child relationship.

    MTI (Multiple Table Inheritance)

    This is the one that’s akin to your first choice above. This is most useful when you need to interact with both the parent and child classes and the children have unique fields of their own (fields, not methods). So a Restaurant might have a cuisine field, but a Place wouldn’t need that. However, they both have an address, so Restaurant inherits and builds off of Place.

    Proxy Models

    Proxy models are like aliases. They cannot have their own fields, they only get the fields of the parent. However, they can have their own methods, so these are useful when you need to differentiate kinds of the same thing. For example, I might create proxy models like StaffUser and NormalUser from User. There’s still only one user table, but I can now add unique methods to each, create two different admin views, etc.

    For your scenario, proxy models don’t make much sense. The children are inherently more complicated than the parent and it wouldn’t make sense to store all the fields like cuisine for Restaurant on Place.

    You could use an abstract Place model, but then you lose the ability to actually work Place on its own. When you want a foreign key to a generalized “place”, you’ll have to use generic foreign keys, instead, to be able to choose from among the different place types, and that adds a lot of overhead, if it’s not necessary.

    Your best bet is using normal inheritance: MTI. You can then create a foreign key to Place and add anything that is a child of Place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a use case with NServiceBus explained in this question. Essentially there is
I have this use case of an xml file with input like Input: <abc
My use case is this... I have a project that has two production branches.
I have this FIFO which I'm going to use to store data from network
I had a test case like this: scenario there should be an SVG tag
In Hotspot, when System.gc() is invoked, I can have this use the Concurrent-Mark-Sweep collector
I have this data: /blabla/blabla (abs,def) /yxz I use this regex (.*)(?:\(([^$]*)\))?\n But it
I have this textbox I use to capture keyboard shortcuts for a preferences config.
hello I have this code that use to sort a datatable. Dim sortingIndex As
Telephone Manager give me Null phone number while i have use this code -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.