Hi there,
I’m having some trouble creating a custom admin page that creates multiple records of the same model, each referencing another model.
Basically, I want a single page that will allow me to view all existing records, and create, update, and destroy those record inline. But, from the point-of-view of the model with the FK.
The scenario is this:
I want to create a home page that will list a few selected links to some other page on my site. The pages these links point to are the detail pages for the existing InformationalObject
model.
To do this, I want the user to first chose which InformationalObjects
can be selected to be shown in the home page. These are the Features
.
Then, the user will select a few of those Feature
s to be the ones actually shown. These are the HomeFeatures
.
Therefore, I have created the two “Feature” models to work with the existing InformationalObject
model:
class InformationalObject(models.Model):
title = models.CharField(
max_length=255,
null=False,
)
class Feature(models.Model):
informational_object = models.ForeignKey(
"InformationalObject",
on_delete=models.CASCADE,
)
name = models.CharField(
max_length=255,
)
class HomeFeature(models.Model):
featured_page = models.ForeignKey(
Feature,
on_delete=models.CASCADE,
)
position = models.PositiveIntegerField()
I don’t want to add a simple inline form for HomeFeature
in the Feature
create/edit form, because it would be cumbersome to go through each Feature
to manage it’s associated HomeFeature
.
The existing HomeFeature
create page, in which I can select a Feature
and position, also doesn’t work well because I have to create one record at a time.
If I could make it so that page has an “Add another” button that allows me to select another Feature
and position, that would do it.
That page, would also show all existing HomeFeatures
and allow me to delete, update, and destroy them.
Is that possible? I`ve been searching for variations of “reverse inline form” or “create multiple records in admin” but can’t find example of how to do this.