I am creating a school management system. Multiple users/school_owners will create multiple classes according to the number of classes in their school. I am the superuser [i.e. Super Admin] that can access classes in every school. So, I want to link classes of a particular school [i.e. Foreign Key] in particular link. And I’ll press that link and the class linked with the foreign key will be display in the list.
It should be like this inside admin :
- School Name 1
- ---- Class 1
- ---- Class 2
- ---- Class 3
- ---- Class 4
- School Name 2
- ---- Class 1
- ---- Class 2
- ---- Class 3
- ---- Class 4
Here school name 1 and school name 2 are the value of the foreign key.
Inside models.py
from django.db import models
from accounts.models import school_details
class student_class(models.Model):
connect_school = models.ForeignKey(school_details, on_delete=models.CASCADE, null=True)
class_list = models.CharField(max_length=95)
def __str__(self):
return self.class_list
So,
connect_school[i.e. `**school name**` ] should be displayed first in theadminand when we click inschool nameit should redirect me to the respectiveclassesof that particular school.
Inside admin.py
from django.contrib import admin
from school.models import student_class
# Register your models here.
admin.site.register(student_class)
This photo denotes how that data is being displayed in an unorganized way with the upper admin.py .
I don’t want like this.
