立即在django管理员中创建多个对象 [英] Create multiple objects in django admin at once
问题描述
例如,我有一个Post模型:
For example, I have a Post model:
Class Post(models.Model):
title = models.Charfield(max_length=200)
# other fields
我想知道有没有办法在管理员中一次性创建多个帖子。换句话说,我需要一个formset而不是在post创建页面上的单一形式。
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.
推荐答案
可能是最好的做法您想要的是扩展 ModelAdmin类
,因为它没有formets,除了在InlineFormsets上使用的那些。
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.
之后,您可以自定义管理员 change_form template ,以包含您的formets
After that you could customize the admin change_form template, to include your formsets
使用admin快速而肮脏的方式将您的Post模型作为另一个modeladmin的内联表单集合,并添加 extra
选项。
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.
这篇关于立即在django管理员中创建多个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!