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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:19:27+00:00 2026-05-16T05:19:27+00:00

Howdy. I’m working on migrating an internal system to Django and have run into

  • 0

Howdy. I’m working on migrating an internal system to Django and have run into a few wrinkles.

Intro
Our current system (a billing system) tracks double-entry bookkeeping while allowing users to enter data as invoices, expenses, etc.

Base Objects
So I have two base objects/models:

  • JournalEntry
  • JournalEntryItems

defined as follows:

class JournalEntry(models.Model):
    gjID = models.AutoField(primary_key=True)
    date = models.DateTimeField('entry date');
    memo = models.CharField(max_length=100);

class JournalEntryItem(models.Model):

    journalEntryID = models.AutoField(primary_key=True)
    gjID = models.ForeignKey(JournalEntry, db_column='gjID')
    amount = models.DecimalField(max_digits=10,decimal_places=2)

So far, so good. It works quite smoothly on the admin side (inlines work, etc.)

On to the next section.
We then have two more models

  • InvoiceEntry
  • InvoiceEntryItem

An InvoiceEntry is a superset of / it inherits from JournalEntry, so I’ve been using a OneToOneField (which is what we’re using in the background on our current site). That works quite smoothly too.

class InvoiceEntry(JournalEntry):
    invoiceID = models.AutoField(primary_key=True, db_column='invoiceID', verbose_name='')
    journalEntry = models.OneToOneField(JournalEntry, parent_link=True, db_column='gjID')
    client = models.ForeignKey(Client, db_column='clientID')

    datePaid = models.DateTimeField(null=True, db_column='datePaid', blank=True, verbose_name='date paid')

Where I run into problems is when trying to add an InvoiceEntryItem (which inherits from JournalEntryItem) to an inline related to InvoiceEntry. I’m getting the error:

<class 'billing.models.InvoiceEntryItem'> has more than 1 ForeignKey to <class 'billing.models.InvoiceEntry'>

The way I see it, InvoiceEntryItem has a ForeignKey directly to InvoiceEntry. And it also has an indirect ForeignKey to InvoiceEntry through the JournalEntry 1->M JournalEntryItems relationship.

Here’s the code I’m using at the moment.

class InvoiceEntryItem(JournalEntryItem):
    invoiceEntryID = models.AutoField(primary_key=True, db_column='invoiceEntryID', verbose_name='')
    invoiceEntry = models.ForeignKey(InvoiceEntry, related_name='invoiceEntries', db_column='invoiceID')
    journalEntryItem = models.OneToOneField(JournalEntryItem, db_column='journalEntryID')
  1. I’ve tried removing the journalEntryItem OneToOneField. Doing that then removes my ability to retrieve the dollar amount for this particular InvoiceEntryItem (which is only stored in journalEntryItem).

  2. I’ve also tried removing the invoiceEntry ForeignKey relationship. Doing that removes the relationship that allows me to see the InvoiceEntry 1->M InvoiceEntryItems in the admin inline. All I see are blank fields (instead of the actual data that is currently stored in the DB).

It seems like option 2 is closer to what I want to do. But my inexperience with Django seems to be limiting me. I might be able to filter the larger pool of journal entries to see just invoice entries. But it would be really handy to think of these solely as invoices (instead of a subset of journal entries).

Any thoughts on how to do what I’m after?

  • 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-16T05:19:28+00:00Added an answer on May 16, 2026 at 5:19 am

    First, inheriting from a model creates an automatic OneToOneField in the inherited model towards the parents so you don’t need to add them. Remove them if you really want to use this form of model inheritance.

    If you only want to share the member of the model, you can use Meta inheritance which will create the inherited columns in the table of your inherited model. This way would separate your JournalEntry in 2 tables though but it would be easy to retrieve only the invoices.

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

Sidebar

Related Questions

Howdy, I have a DataRow pulled out of a DataTable from a DataSet. I
Howdy... here on my local LAN, I have a Windows Server 2k8 box with
Howdy, I'm writing a batch script that will run on a Windows XP machine.
Howdy, codeboys and codegirls! I have came across a simple problem with seemingly easy
Howdy! I'm working on an old project from one of my programming courses and
Howdy. Consider the following: SQL> DECLARE 2 b1 BOOLEAN; 3 b2 BOOLEAN; 4 FUNCTION
What I want is, I think, relatively simple: > Bin = <<Hello.world.howdy?>>. > split(Bin,
Howdy and Thanks in Advance! I'm trying to access the USB port from a
Howdy! I am looking for a way to list all of the image files
Howdy all. I am trying to solve a problem which is apparently not uncommon

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.