Using breadcrumbs with django-filter, QueryDict trouble
I'm using django-filter to drill down and would开发者_运维知识库 like to create breadcrumbs for each item that was filtered. For example:
Price ranges:
10,000+
5,000-9,999
1,000-4,999
0-999
Bedrooms:
4
3
2
1
Each of the items under Price ranges and Bedrooms would be a link to drill down in a queryset.
I'd like to create a breadcrumb such as Price range 0-999
or Bedrooms 3
if the user were to click those links, and then show Price range 0-999 > Bedrooms 3
or Bedrooms 3 > Price range 0-999
when they click a second link.
The breadcrumbs should maintain order (the part I'm having trouble with) and work for any number of attributes. Clicking a link in the breadcrumb trail should apply the filter clicked on and all filters before it in the trail.
I'd like to create an empty QueryDict
and then iterate through request.GET to build the QueryDict
up as I output the breadcrumbs, but for some reason QueryDict
iterates through its elements backwards (see the documentation).
What's the cleanest way to accomplish this? Does anyone know why QueryDict
works this way? (I imagine there's a use-case I'm missing.) Any advice is appreciated.
keep track of the order in sessions. so when the first filter is clicked (eg 3 beds) store it. then if another one is clicked, build your bread crumbs from sessions. say the second one was 0-999 you'd pull any existing breadcrumbs (in this example you'd find the 3 beds) and then tack on the latest (0-999).
精彩评论