在django admin中动态添加行内联 [英] Add row to inlines dynamically in django admin

查看:396
本文介绍了在django admin中动态添加行内联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下定义:

class AnswerChoiceInline(admin.TabularInline):
    model = AnswerChoice
    # extra = 0


class QuestionAdmin(admin.ModelAdmin):
    inlines = [AnswerChoiceInline]


admin.site.register(Question, QuestionAdmin)

显然我得到了默认的附加设置(默认为3)。管理员目前有没有一种方式将添加另一行添加到内联字段集?所以我可以填写3行,如果我需要一个第四个,我可以点击一个链接或按钮,并添加一个额外的行?

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

推荐答案

为什么要查看添加和删除Django管理员内嵌JavaScript 由Arne Brodowski。

Why yes, check out Add and remove Django Admin Inlines with Javascript by Arne Brodowski.

这篇关于在django admin中动态添加行内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆