Opened 7 years ago
Closed 7 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 , 7 years ago
| Triage Stage: | Unreviewed → Ready for checkin |
|---|
comment:2 by , 7 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
In 7c3a8b9: