Django object extension / one to one relationship issues <p>Howdy. I'm working on migrating an internal system to Django and have run into a few wrinkles.</p> <p><b>Intro</b><br> Our current system (a billing system) tracks double-entry bookkeeping while allowing users to enter data as invoices, expenses, etc.</p> <p><b>Base Objects</b><br> So I have two base objects/models:</p> <ul><li>JournalEntry <li>JournalEntryItems </ul> <p>defined as follows:</p> <pre> 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) </pre> <p>So far, so good. It works quite smoothly on the admin side (inlines work, etc.)</p> <p><b>On to the next section.</b><br> We then have two more models</p> <ul><li>InvoiceEntry <li>InvoiceEntryItem </ul> <p>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.</p> <pre> 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') </pre> <p>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:</p> <pre> &lt;class 'billing.models.InvoiceEntryItem'&gt; has more than 1 ForeignKey to &lt;class 'billing.models.InvoiceEntry'&gt; </pre> <p>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.</p> <p>Here's the code I'm using at the moment.</p> <pre> 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') </pre> <ol> <li><p>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).</p></li> <li><p>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).</p></li> </ol> <p>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).</p> <p>Any thoughts on how to do what I'm after?</p>