Here is what my admin page looks like:
As I add more models, I will have more foreign keys related to Selector and each instance of the selector model doesn’t need all the inlines. I would like to be able to select and choose which inlines to display for simplicity of the admin page. Does anyone have any suggestions on how I can simplify my page and have a dropdown multiple select box for dynamically displaying the inlines?
Here is my models.py file:
from django.db import models
class Selector(models.Model):
lst = [
("Model1", "Model1"),
("Model2", "Model2"),
("Model3", "Model3"),
("Model4", "Model4"),
]
choice = models.CharField("Choices", choices=lst, max_length=40)
class Model1(models.Model):
select = models.ForeignKey(Selector, on_delete=models.CASCADE)
param1 = models.IntegerField("Input 1")
param2 = models.IntegerField("Input 2")
param3 = models.IntegerField("Input 3")
class Model2(models.Model):
select = models.ForeignKey(Selector, on_delete=models.CASCADE)
param1 = models.IntegerField("Input 1")
param2 = models.IntegerField("Input 2")
param3 = models.IntegerField("Input 3")
class Model3(models.Model):
select = models.ForeignKey(Selector, on_delete=models.CASCADE)
param1 = models.IntegerField("Input 1")
param2 = models.IntegerField("Input 2")
param3 = models.IntegerField("Input 3")
class Model4(models.Model):
select = models.ForeignKey(Selector, on_delete=models.CASCADE)
param1 = models.IntegerField("Input 1")
param2 = models.IntegerField("Input 2")
param3 = models.IntegerField("Input 3")
Here is my admin.py file:
from django.contrib import admin
from .models import Model1, Model2, Model3, Model4, Selector
class Model1Admin(admin.TabularInline):
model = Model1
extra = 1
class Model2Admin(admin.TabularInline):
model = Model2
extra = 1
class Model3Admin(admin.TabularInline):
model = Model3
extra = 1
class Model4Admin(admin.TabularInline):
model = Model4
extra = 1
class SelectorAdmin(admin.ModelAdmin):
model = Selector
inlines = [Model1Admin, Model2Admin, Model3Admin, Model4Admin]
admin.site.register(Selector, SelectorAdmin)