Opened 7 years ago

Closed 7 years ago

#29431 closed Cleanup/optimization (needsinfo)

inline_admin should have possibility don't generate empty inline form.

Reported by: Maxim Danilov Owned by: Daniel Rios
Component: contrib.admin Version:
Severity: Normal Keywords: InlineFormSet, optimization
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Daniel Rios)

for example in admin.py:

class my_model_inline(admin.StackedInline):
	can_add_empty = False

django/contrib/admin/templates/admin/edit_inline/stacked.html after {% for inline_admin_form in inline_admin_formset %}

{% if opts.can_add_empty or not forloop.last %}

this helped don't call a formset.empty_form, if i dont need it.

but it is better check it already in: InlineAdminFormSet.iter(self), last iteration.
I think, it makes django better and give more speed.

Change History (4)

comment:1 by Maxim Danilov, 7 years ago

Description: modified (diff)

comment:2 by Daniel Rios, 7 years ago

Owner: changed from nobody to Daniel Rios
Status: newassigned

comment:3 by Daniel Rios, 7 years ago

Description: modified (diff)

Hi danilovmy,

I'm having trouble reproducing the feature you mention.
Could you provide the whole line from django/contrib/admin/templates/admin/edit_inline/stacked.html on which the tag should appear, with the new property?

Second, is this different from turning off the add permission? This method on the Inline removes the blank fields, but also removes the ability to add a blank form with the Add another Item bar below the forms. See: https://docs.djangoproject.com/en/2.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.has_add_permission

def has_add_permission(self, request):
    return False

Please feel free to re-open the ticket with more info.

comment:4 by Daniel Rios, 7 years ago

Resolution: needsinfo
Status: assignedclosed
Note: See TracTickets for help on using tickets.
Back to Top