How to create multiple records from admin

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 Features 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.

You don’t want to.

You’re going well beyond what the admin is designed to do, and while you might be able to make this work as you’re intending, it’s really not a good practice to try and do this sort of thing with the admin.

Quoting directly from the docs:

The admin’s recommended use is limited to an organization’s internal management tool. It’s not intended for building your entire front end around.

and

If you need to provide a more process-centric interface that abstracts away the implementation details of database tables and fields, then it’s probably time to write your own views.

I suggest you take the official advice literally and to heart, and stop trying to build your application as an extension to the admin. Experience has taught me (and numerous others) that you can quickly get to the point where you’re spending a lot more time trying to get the admin to do what you want then the time you’ll spend cranking out some custom views.

1 Like

Got it. It makes perfect sense. I’ve read that part of the documentation and it resounded with me.

I thought about going this way in this particular feature, because it’s not going to be more complex than that, and it seemed like a small step beyond what the admin already provides.

I can certainly crank out a custom view to do exactly what I want, and I have already spent too much time trying to do it via the admin.

Thanks