Opened 5 years ago

Closed 5 years ago

#30243 closed Cleanup/optimization (fixed)

Reduce structural dependency in contrib.admin 'has_file_field' checks

Reported by: btknu Owned by: btknu
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

This ticket is about a very small cleanup. It's possible that a Trac ticket isn't necessary for this, I decided to make one to stay on the safe side.

The PR https://github.com/django/django/pull/9298 for ticket https://code.djangoproject.com/ticket/28585 adds code:

            'has_file_field': context['adminform'].form.is_multipart() or any(
                admin_formset.formset.form().is_multipart()
                for admin_formset in context['inline_admin_formsets']
            ),

This snippet invokes is_multipart() on formset's form() object.
But the formset (specifically: BaseFormSet) already provides an is_multipart() method.

It feels cleaner to rely on a single place to calculate is_multipart for a formset.
This way if is_multipart logic gets more complex, we only need to update it in one place and there's less risk of bugs.

I suggest replacing:

admin_formset.formset.form().is_multipart()

with:

admin_formset.formset.is_multipart()

Change History (2)

comment:1 by Simon Charette, 5 years ago

Triage Stage: UnreviewedReady for checkin

comment:2 by Tim Graham <timograham@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 7c3a8b9:

Fixed #30243 -- Simplified ModelAdmin.render_change_form()'s has_file_field.

Note: See TracTickets for help on using tickets.
Back to Top