在 django admin 中动态添加行到内联
我定义了以下内容:
class AnswerChoiceInline(admin.TabularInline):
model = AnswerChoice
# extra = 0
class QuestionAdmin(admin.ModelAdmin):
inlines = [AnswerChoiceInline]
admin.site.register(Question, QuestionAdmin)
显然我得到了默认的额外设置(默认为 3)。 当前是否有一种内置于管理员中的方法可以将“添加另一行”到内联字段集? 所以我可以填写 3 行,如果我需要第四行,我可以单击链接或按钮,并让它添加额外的行?
现在我的工作流程要么将“额外”设置为任意大的数字,然后只有空白行,要么让用户多次保存模型(以便显示额外的行)。
I have the following defined:
class AnswerChoiceInline(admin.TabularInline):
model = AnswerChoice
# extra = 0
class QuestionAdmin(admin.ModelAdmin):
inlines = [AnswerChoiceInline]
admin.site.register(Question, QuestionAdmin)
Obviously I get the default extras setting (default is 3). Is there a way built into the admin currently to 'Add another row' to the inline fieldset? So I can fill in say 3 rows, and if I need a 4th I can click a link or button, and have it add an additional row?
Right now my work flow is either set 'extra' to an arbitrarily large number and then just have blank rows or make the user save the model multiple times (so that the extra rows show up).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么是的,请查看 添加并删除 Arne Brodowski 的 Django Admin Inlines with Javascript。
Why yes, check out Add and remove Django Admin Inlines with Javascript by Arne Brodowski.