Persistent change_list filtering in admin
|Reported by:||Owned by:||nobody|
|Cc:||Mikhail Korobov||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||yes||Patch needs improvement:||yes|
Attached is a patch which allows the list_filters on the change_list pages of the admin to be persistent (as described in e.g. this thread on django-users). Basically, it does this:
- Saves the elements of the query string in the session each time the change_list is viewed.
- Looks for a special GET variable, and if found, restores the items last saved from the query string.
- Add the special GET variable to links and redirects from the change_form, so that when saving an object, the user is redirected back to the filtered list s/he was last viewing.
I'm not entirely sure this is the best way to solve this issue; something more transparent (i.e. without a magic GET variable) might be better, in which case the change_list filter links would have to explicitly unfilter themselves, rather than simply removing the query variable.
The patch admittedly also adds a setdefault method to request.session; the rest of the patch could trivially be adapted to not having this method available, of course.. I've found it useful on many occasions, though, and it seems to fit the "use session as dictionary" idea. If folks find the patch useful, I can resubmit with documentation and/or without request.session.setdefault.
Change History (12)
comment:6 Changed 6 years ago by
comment:7 Changed 6 years ago by
|Cc:||Mikhail Korobov added|
|Patch needs improvement:||set|
|Status:||closed → reopened|
|Type:||Uncategorized → New feature|