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

  • Home
  • SEARCH
  • 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 904447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:03:06+00:00 2026-05-15T16:03:06+00:00

I have this models: class BillHeader(models.Model): billno = models.IntegerField(primary_key=True, blank=True) class BillData(models.Model): price =

  • 0

I have this models:

class BillHeader(models.Model):
    billno = models.IntegerField(primary_key=True, blank=True)

class BillData(models.Model):
    price = models.DecimalField(_('Price'), max_digits=12, decimal_places=2)
    amount = models.DecimalField(_('Amount'), max_digits=6, decimal_places=2)

    [... rest of the model ...]

    class Meta:
        abstract = True

class BillFooter(models.Model):
    total = models.DecimalField(_('Total'), max_digits=12, decimal_places=2)

    [... rest of the model ...]

    class Meta:
        abstract = True

BillData and BillFooter are common to every BillHeader so I’ve marked them as abstract. Can I do class BillHeader(BillData, BillFooter) or I’m doing something wrong?

I also thought about doing BillData the main one, and BillHeader BillFooter abstract. I don’t have any experience on doing data models (at least not complex ones) and I’m a bit lost. What would you recommend?

  • 1 1 Answer
  • 4 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-15T16:03:06+00:00Added an answer on May 15, 2026 at 4:03 pm

    Yes, a Django model can inherit from as many abstract base classes as you like, as long as they don’t result in an ambiguous “model resolution order”. Think of inheritance as a chain… each class you inherit from is a link in the chain. Inheriting from two base classes is just adding two links to the chain instead of one.

    In other words, if your abstract base classes inherit from models.Model, then don’t try to inherit from both the abstract base class and models.Model in your Bill class. models.Model is already in the inheritance chain, so inheriting from it causes chaos in the chain of base classes.

    As to how I would structure these classes, I would create a model called Bill that inherited from BillHeader, BillData, and BillFooter. The reason for this is that I like my Django models to represent discrete objects (e.g. Bill, Article, BlogPost, Photo, etc.)

    However, the point of abstract base classes is to be able to add a level of abstraction to common fields and methods so that multiple classes can inherit from them. If you’re just creating a Bill class it’s somewhat meaningless. If, however, you had Bill, and UnpaidBill, and PaidBill… all of those would have common fields that should appear on all of them and you can save yourself a lot of trouble by abstracting to an ABC.

    Hopefully that offers a little insight to what ABC’s and inheritance are good for.

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

Sidebar

Related Questions

I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code,
I have two models like this: class ClassA(models.Model): ida = models.AutoField(primary_key=True) classb = models.ForeignKey(ClassB)
I have this model class Vacancy(models.Model): user = models.ForeignKey(User, null=True, blank=True, default = None)
I have this models: class Balanta(models.Model): data = models.DateField() class Conturi(models.Model): cont=models.PositiveIntegerField() cont_debit=models.DecimalField(default=0, max_digits=30,
Let's see if I can explain myself, I have this models: class BillHeader(models.Model): number
For Django 1.1. I have this in my models.py: class User(models.Model): created = models.DateTimeField(auto_now_add=True)
In Django I have this: models.py class Book(models.Model): isbn = models.CharField(max_length=16, db_index=True) title =
I have this in my models.py: class AuditableTable(models.Model): class Meta: abstract = True created_by
I have this model: class People(models.Model): name = models.CharField(max_length=128, db_index=True) friends = models.ManyToManyField('self') So
assume I have this little model: class Deal(models.Model): purchases = models.IntegerField(default=0)#amount of purchases so

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.