I’m trying to figure out how to get the django admin system to display my models as inlines, when there isn’t a direct FK from child to parent model.
I have three models (pseudo code):
class CampaignMain(models.model):
...
class CampaignMonitor(models.model):
campaign = models.OneToOneField(CampaignMain, pk=True)
class CampaignTransaction(models.model):
campaign = models.ForeignKey(CampaignMain)
So both CampaignMonitor and CampaignTransaction FK CampaignMain, which is the way I need it to be structured.
Here’s the bit I can’t fathom: I need an admin page showing CampaignMonitor with CampaignTransaction as inlines. But when I try this, I get “error no fk in CampaignTransaction pointing to CampaignMonitor”
Is there a way to “force” the relationship just for the admin page? Or is there a generic FK option? I saw something in contrib/contenttypes, but it doesn’t seem to be what I need. Or am I going to have to build a custom admin section to two models in that way?
As always advice is greatly appreciated.
imanc
Instead of OneToOneField you can use Multi-table inheritance, which implemented using a one-to-one relationshinp:
Now modify CampaignMonitor’s admin as needed for your needs.