Login

Snippets by rhfung

Snippet List

Keeping filter states after edits (Django 1.4)

When saving an edit to an object from a filtered list view you are, by default, returned to list view without any of your filters applied. This solves that problem, keeping the filtered view in a session variable until you reach a point where the session key is deleted. This solution doesn't require changes to template code...this is completely self contained within your own admin.py files. The solution presented here is a revision of a previous patch, which has been modified for Django 1.4. The Django 1.3 version exists at: http://djangosnippets.org/snippets/2531/ From chronosllc: The advantage to our solution over the above linked solution is that under different use cases the user may or may not be redirected to the filtered list_view. For example, if you edit an object and click the save and continue button, then you would lose the filter when you finally finished editing the object and clicked save. Added on here is a delete of the session key when users add objects, the reasoning we're going this route is we don't want to return users to filtered views when they just added a new object. Your mileage may vary and if so, it's easy enough to fit your own needs.

  • filter
  • admin
  • change_list
Read More

rhfung has posted 1 snippet.