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?
I had to set extra and min_num for this to work
class MyInline(admin.TabularInline):
extra = 0
min_num = 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With