djangosession-variablesuser-preferences

Django remember user preference for his next request


There's a shop where the user can filter the products using the categories of a menu. Each category has subcategories. Let's say the categories of the menu are: age, sex, skill, brand. Whenever the user clicks one of the category all the related products are displayed. When he clicks a subcategory, the parent category (including the subcategories) is hidden. Right now only the items related to the chosen subcategory are displayed. Whenever the user clicks another subcategory an "AND" operation is done between all the chosen subcategoris. At some point the visible products will be all part of 2 years, male, memory, XXX.

In order to achieve that a request variable has to be used to store the user preference anytime he clicks a new subcategory. I know it's possible to use javascript to compose the url like myreq/age=2&sex=male ...I don't want to use that. Another idea would be to set a cookie, request variable...

Which is the best solution to "track" the user actions. Where should the data be stored? As the search criteria is only temporary I wouldn't use a DB to store the data. The "tracking" (implicitly the "AND" operation) is reinitialized whenever the user clicks a category (the combination of the filters is active as long as the user clicks subcategories).


Solution

  • This is exactly what the sessions framework is for.