Tuesday, July 26, 2016

Best way to keep the current selection

I'm wondering if there's a better way to maintain a selection of records across calls to the app.

In one of my projects users can do ad-hoc searches; i.e., Last Name = Smith, Class Name = Yoga, etc.

They do the search, then get the query results presented in a table.

Then they can do things with the selection like run reports or make it the basis for further queries. 

To maintain state, after any ad-hoc query, I store the ids for the found records:

self.request.session['query.classes.last_ids'] = list(queryset.values_list('id', flat=True))

It works fine and I've not had any problems I can lay to this. But I'm executing the query at least twice and I'm storing, potentially, thousands of ids in the session cache.

The only other alternative I've thought of was to store the query criteria and re-execute it, but a) that's complicated and b) the underlying results could change while the user is deciding on the next step.

Is there a best practice for this sort of thing?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BePoMw6EOf%2B4%3DYPkutNeyqddYBGEPXjhg%2BeLr4eB2q7VBkihw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment