I need to maintain a list of filtered and sorted objects, preferably in a generic manner, that can be used in multiple views. This is necessary so I can generate next, prev links, along with some other very useful things for the user.
Examples of filters:
field__isnull=True
field__exact="so"
field__field__isnull=False
Additionally, after the filtered query set is built, ordering may be applied by any of the fields.
My current solution is to use a FilterSpec class containing a collection of filters, along with an initial query set. This class is then serialized and passed to a view.
Consider a view with 25 dynamically filtered items. Each item in the view has a link to get a detailed view of the item. To each of these links, the serialized FilterSpec object of the current list is appended. So you end up with huge urls. Worse, the same huge filter is appended to all 25 links!
Another option is to store the FilterSpec in the session, but then you run into problems of when to delete the FilterSpec. Next you find all your views getting cluttered with code trying to determine if the filter should be deleted in preparation for a new list of objects.
I'm sure this problem has been solved before, so I'd love to hear other solutions that you guys have come up with.