[Fixed]-Simple way to show group members in Django Admin?

1👍

You can use the InlineModelAdmin objects particularly the TabularInline object. Sample code below will let you edit the list of Players belonging to a particular division.

# admin.py
from django.contrib import admin

class PlayerInline(admin.TabularInline):
    model = Player

class DivisionAdmin(admin.ModelAdmin):
    inlines = [
        PlayerInline,
    ]

As for being able to edit the Division from the Player model, you should already be able to do that, unless you removed it from the list of editable fields. If you plan to change that to a ManyToManyField, you will need to create a through model (e.g. Membership) and create the inlines like so:

# admin.py
from django.contrib import admin

class MembershipInline(admin.TabularInline):
    model = Membership

class DivisionAdmin(admin.ModelAdmin):
    inlines = [
        MembershipInline,
    ]

class PlayerAdmin(admin.ModelAdmin):
    inlines = [
        MembershipInline,
    ]

Leave a comment