Skip to content
Advertisement

Django Admin set extra to 0 when editing

Setting extra = 1 in my model always shows a 1 empty field. It is OK while inserting a new item but I don’t want to show an additional empty field while editing. How can I do this?

models.py:

JavaScript

admin.py:

JavaScript

Advertisement

Answer

Override the get_extra method instead of setting a value for extra class member.

Returns the number of extra inline forms to use. By default, returns the InlineModelAdmin.extra attribute.

Override this method to programmatically determine the number of extra inline forms. For example, this may be based on the model instance (passed as the keyword argument obj):

Something like:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement