Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add row to inlines dynamically in django admin

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

like image 736
ashchristopher Avatar asked Dec 03 '25 22:12

ashchristopher


1 Answers

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

like image 197
Van Gale Avatar answered Dec 05 '25 16:12

Van Gale



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!