5

For example, I have a Post model:

Class Post(models.Model):
    title = models.Charfield(max_length=200)
    # other fields

I wonder is there a way to create multiple posts at once in admin. In other words, I need a formset instead of single form on post creation page.

2 Answers 2

7

I've heard recently about a django app that exactly does this job. It's called django-bulk-admin and enables bulk add/update in the admin.

Sign up to request clarification or add additional context in comments.

5 Comments

They are doing exactly what I told, they have created BulkModelAdmin that extends ModelAdmin Class and add formsets. Then they've created templates for change_form.
@FernandoFreitasAlves : you're right ! I didn't investigate, in fact I just found the package on Reddit and thought the OP would be interested by a third-party answer instead of writing it from scratch.
@EliotBerriot But fields cannot be excluded with this! And what about model_save method overriding? Is that possible?
@edam to be honest, I never used the package so I don't really know. You'll have to look in the package code itself or open an issue to ask your question :)
The module does not support django 3+, the last commit was in 2015.
2
+50

Possibly, the best way to do exactly what you want is extend the ModelAdmin class, because it has no formsets on it, except for those used on InlineFormsets.

After that you could customize the admin change_form template, to include your formsets

The quick-and-dirty way to do it using admin is wrap your Post model as an inline formset of another modeladmin and add the extra option to it.

2 Comments

1) I want to explicitly mark those models, that need a formset. I guess, your solution is non-selective and will make all models look the same. 2) Inline is not what I'm looking for.
Ok, you still need to create a new ModelAdmin class with a formset property and a formset flag, marking if you want the specific admin form to use formsets and the number of extra_forms. @chem1st

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.