[Django]-Django admin more than one ForeignKey for admin.TabularInline

45👍

This solved my problem (using fk_name):

class Fights(admin.TabularInline):
    model = FighterFightHistory
    extra = 30
    fk_name = 'fighter'

2👍

My first thought was, that you could use ManyToMany-Fields and then limit the number of relations to two. But then I thought, that you never can be sure which Fighter-Object represents which type.

Then I had a short look into the Django-Docs and found something that should answer your problem: Django-Doc

The interesting part is:

Membership has two foreign keys to Person (person and inviter), which makes the relationship ambiguous and Django can’t know which one to use. In this case, you must explicitly specify which foreign keys Django should use using through_fields, as in the example above.

I hope that this helps you.

Leave a comment