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 407327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:35:01+00:00 2026-05-12T17:35:01+00:00

I am attempting model inheritance on my Django powered site in order to adhere

  • 0

I am attempting model inheritance on my Django powered site in order to adhere to DRY. My goal is to use an abstract base class called BasicCompany to supply the common info for three child classes: Butcher, Baker, CandlestickMaker (they are located in their own apps under their respective names).

Each of the child classes has a need for a variable number of things like email addresses, phone numbers, URLs, etc, ranging in number from 0 and up. So I want a many-to-one/ForeignKey relationship between these classes and the company they refer to. Here is roughly what I imagine BasicCompany/models.py looking like:

from django.contrib.auth.models import User
from django.db import models

class BasicCompany(models.Models)
    owner = models.ForeignKey(User)
    name = models.CharField()
    street_address = models.CharField()
    #etc...

    class Meta:
        abstract = True

class EmailAddress(models.model)
    email = models.EmailField()
    basiccompany = models.ForeignKey(BasicCompany, related_name="email_addresses")

#etc for URLs,  PhoneNumbers, PaymentTypes.

What I don’t know how to do is inherit EmailAddress, URLs, PhoneNumbers (etc) into the child classes. Can it be done, and if so, how? If not, I would appreciate your advice on workarounds.

  • 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-12T17:35:02+00:00Added an answer on May 12, 2026 at 5:35 pm

    I suspect you’ll be better off with generic relations for the links, rather than trying to tie everything to a base class. Generic relations allow you to link a model such as EmailAddress to any other class, which would seem to be a good fit with your use case.

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

Sidebar

Related Questions

so django-model-utils is awesome. I'm on django 1.3 and attempting to use the Inheritance
I'm attempting to use a Model but I get a fatal error so I
I'm attempting to extend django's contrib.auth User model, using an inline 'Profile' model to
I have a vote model, which has a class method called score . Basically,
attempting to use this railscast as a guide: http://railscasts.com/episodes/197-nested-model-form-part-2?view=asciicast and running into this error:
For a model like: class Item(models.Model): notes = models.TextField(blank=True) .... I'm attempting to do
I'm attempting to dynamically construct some classes which are subclasses of django's models.Model. My
I'm attempting to use RIA services with a Entity Framework back end. The Model
I'm currently working on a django project. I'm attempting to add a UserProfile model
I'm attempting to create a formset for the following models: class Category(models.Model): name =

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.