Add row to inlines dynamically in django admin

断了今生、忘了曾经 提交于 2019-12-21 05:41:09

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/520421/add-row-to-inlines-dynamically-in-django-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!