[Solved]-Django Admin, accessing reverse many to many



You have to use inlines in your admin pages.

in your admin.py

from __future__ import unicode_literals
from django.contrib.auth.admin import UserAdmin
from django.contrib import admin
from django.contrib.auth import get_user_model
from .models import Company

User = get_user_model()

class CompanyInline(admin.TabularInline):
    model = Company.users.through

class MyUserAdmin(UserAdmin):
    inlines = [CompanyInline, ]

class CompanyAdmin(admin.ModelAdmin):

You can read more about this in docs here

There are several options available for Inlines (for example – stacked/inline, collapse, extra, min etc) you can read more about it in the docs


Leave a comment