Opened 7 months ago

Closed 7 months ago

#29431 closed Cleanup/optimization (needsinfo)

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

Reported by: danilovmy 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 Changed 7 months ago by danilovmy

Description: modified (diff)

comment:2 Changed 7 months ago by Daniel Rios

Owner: changed from nobody to Daniel Rios
Status: newassigned

comment:3 Changed 7 months ago by Daniel Rios

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 Changed 7 months ago by Daniel Rios

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