6
votes

I am making a web game in which each world can be part of one alliance.

class World(models.Model):
    # rest of Model
    alliance = models.ForeignKey('Alliance', related_name='allmember', default=None, blank=True, null=True)
    officer = models.NullBooleanField()
    leader = models.NullBooleanField()

class Alliance(models.Model):
    allianceid = models.AutoField(primary_key=True)
    alliance_name = models.CharField(max_length=20, unique=True)
    alliance_desc = models.TextField(max_length=200)

I gather that using inlines, I can display the members of an alliance on the alliance page. However, I can only edit the officer and leader statuses, whereas I want to be able to edit the membership status as well. Here is the inline I am using.

class MemberInline(admin.TabularInline):
    model = World
    fk_name = 'alliance'
    # excludes

class AllianceAdmin(admin.ModelAdmin):
    inlines = [
        MemberInline,
    ]

I suppose what I really want to ask is if I can edit a foreign key relationship in the admin site from the target model rather than the originator.

1
What membership status? - Daniel Roseman
I'd like to be able to edit whether a world is in an alliance from the alliance page. - heidi
But you can do that already - there's automatically a dropdown for alliance on the World admin form. - Daniel Roseman
True, but like I said, I want to able to edit this from the Alliance admin form. After all, if I'm managing members of an alliance it makes sense for me to be able to do this from the alliance form rather than having to go to each individual member form. - heidi
@heidi maybe this is helpful stackoverflow.com/a/42374899/767834 - felix

1 Answers

-1
votes

It´s very old post but is good for reference. This should work! Did you pass the AllianceAdmin to the register function?

admin.site.register(Alliance, AllianceAdmin)