#36708: `formset` not a static attribute of `ChangeList`
-------------------------------------+-------------------------------------
Reporter: Ben Gregory | Owner: Ben
Type: | Gregory
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution:
Keywords: ChangeList | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):
* cc: Antoliny (added)
* keywords: => ChangeList
Comment:
Thank you for suggesting the improvements Ben!
You're absolutely right, when the `result_list` template tag renders the
template, the changelist must have a `formset` attribute.
{{{
def results(cl):
if cl.formset:
for res, form in zip(cl.result_list, cl.formset.forms):
yield ResultList(form, items_for_result(cl, res, form))
else:
for res in cl.result_list:
yield ResultList(None, items_for_result(cl, res, None))
def result_list(cl):
"""
Display the headers and data list together.
"""
headers = list(result_headers(cl))
num_sorted_fields = 0
for h in headers:
if h["sortable"] and h["sorted"]:
num_sorted_fields += 1
return {
"cl": cl,
"result_hidden_fields": list(result_hidden_fields(cl)),
"result_headers": headers,
"num_sorted_fields": num_sorted_fields,
"results": list(results(cl)),
}
}}}
And as you mentioned, this attribute is currently being dynamically
assigned in the `changelist_view` through the options.py.
I also agree that defining the formset attribute directly in the
`ChangeList` class would be more appropriate.
I agree with this improvement, but there might be aspects I haven’t
considered, so I’ll wait for another person’s triage :)
--
Ticket URL: <
https://code.djangoproject.com/ticket/36708#comment:1>