Please help to understand how to display list of groups in Django admin Person instance in this case:
class Person(models.Model):
name = models.Charfield(max_length=120)
class Group(models.Model):
title = models.Charfield(max_length=120)
persons = models.ManyToManyField(Person)
You need to use inlines
. Add this to the admin.py
file:
from .models import Group
class GroupInline(admin.TabularInline):
model = Group.persons.through
extra = 1
class PersonAdmin(admin.ModelAdmin):
inlines = [GroupInline]
admin.site.register(Person, PersonAdmin)
See details here.