[Django]-Django admin multiple querysets on one page

2👍

You can use InlineModelAdmin objects to implement this, although if you want to do nested inlines you should check out this post. Although as that post says:

…it would be a kind of convoluted design to implement.

You didn’t provide any code here so the best I can do is guess your model relationships.

models.py

from django.db import models


class Department(models.Model):
    name = models.CharField(max_length=250)
    ...

class Employee(models.Model):
    name = models.CharField(max_length=250)
    ...

class Company(models.Model):
    name = models.CharField(max_length=250)
    departments = models.ForeignKey(Department)
    employees = models.ForeignKey(Employee)
    ...

admin.py

from django.contrib import admin


class EmployeeInline(admin.StackedInline):
    model = Employee

class DepartmentInline(admin.StackedInline):
    model = Department

class CompanyAdmin(admin.ModelAdmin):
    list_display = ('name')
    inlines = [DepartmentInline, EmployeeInline]

admin.site.register(CompanyAdmin)

Leave a comment