Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin inlines - minimum number of forms

When creating custom model admin inlines in Django, you can set two parameters extra and max_num: the number of additional forms to display, and the maximum number of objects to allow the user to attach to the parent object.

I have a Question model, each of which can have several answers, which are inlines in the Question admin. Most questions will have three answers, so I would like to show three inlines by default; however, when editing a question that already has three answers, it looks crowded and tacky to show three whole extra fields when most likely there aren't going to be any more answers at all. What I want is essentially a min_num parameter: I want to show at least three fields by default, empty if there are less than three answers already, while still allowing the user to add more than that which will then all be shown.

I've found tickets for adding this both to formsets and inlines, but it looks like they haven't been resolved. Is there any convenient way to do this in Django 1.4 currently?

like image 363
antialiasis Avatar asked Oct 02 '12 15:10

antialiasis


1 Answers

I had to set extra and min_num for this to work

class MyInline(admin.TabularInline):
    extra = 0
    min_num = 3
like image 199
Andriod Avatar answered Oct 19 '22 14:10

Andriod