#36708: `formset` not a static attribute of `ChangeList`
-------------------------------------+-------------------------------------
Reporter: Ben | Owner: Ben Gregory
Gregory |
Type: | Status: assigned
Cleanup/optimization |
Component: | Version: 5.2
contrib.admin |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The `ChangeList` class is used in Django Admin to determine and configure
the functionality of a model's `change_list` admin page.
I have been experimenting with using `ChangeList` for my own purposes, to
create a custom page not dissimilar to `change_list.html`.
I have noted that in doing so, I have needed to set the attribute `formset
= None` on my `ChangeList` instance, to satisfy an expectation of the
`admin_list.result_list`
[https://github.com/django/django/blob/e27cff68a32a0183c6b8d110b359c1c858f68cd7/django/contrib/admin/templatetags/admin_list.py#L328
template tag]. This is because `formset` is not a static attribute of the
class.
Looking at the source code, the
[https://github.com/django/django/blob/e27cff68a32a0183c6b8d110b359c1c858f68cd7/django/contrib/admin/options.py#L2056
`django.contrib.admin.options`] module sets `formset` on the `ChangeList`
instance.
Outside of tests, `ChangeList` objects are only instantiated in the above
module, and as said above, will always be assigned a `formset` attribute.
See
[https://github.com/search?q=repo%3Adjango%2Fdjango+%2F%28%3F-i%29ChangeList%2F+language%3APython&type=code&l=Python
here]. So, it appears to me that there is an assumption that instances of
this class should _always_ have a `formset` attribute.
I propose we simply make `formset` an attribute of `ChangeList`, rather
than assign it dynamically in the aforementioned function. This will mean
developers working low-level in the admin needn't write a line of code to
be able to use their custom `ChangeList` objects with the relevant
template tags, and will serve to better document the expected attributes
of `ChangeList` objects more generally.
Proposal:
https://github.com/django/django/blob/e27cff68a32a0183c6b8d110b359c1c858f68cd7/django/contrib/admin/views/main.py#L67:
{{{
+ formset = None
}}}
https://github.com/django/django/blob/e27cff68a32a0183c6b8d110b359c1c858f68cd7/django/contrib/admin/options.py#L2056:
{{{
- formset = cl.formset = None
+ formset = None
}}}
One could also argue that this is an opportunity to remove this notation
`formset = cl.formset = *`, and use `cl.formset` directly.
--
Ticket URL: <https://code.djangoproject.com/ticket/36708>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019a4f5cc540-d005e64f-29db-4d50-bc29-18f675432b32-000000%40eu-central-1.amazonses.com.