How would you do this cleanly in Django (remembering the states of check boxes in multiple pages)

50 views
Skip to first unread message

Chi-Cheong Weng

unread,
May 8, 2014, 9:18:23 AM5/8/14
to django...@googlegroups.com
Hi guys,

I have been using Django for a little more than a year now, but I still cannot think of a clean way of achieving this:

Let's say I have 1000 products in the db and I want to create a campaign to promote the products. I am displaying the products 100 items each time and each item has a check box. I want to be able to go back and forth between different pages to select products and then when I hit the submit button, the server will know what products I select.

How would you do this? Will you use other technology stack such as ajax, jquery, etc?

Thanks.

François Schiettecatte

unread,
May 8, 2014, 9:27:36 AM5/8/14
to django...@googlegroups.com
I would create a number of DIVs, put 100 production in each DIV and then show/hide the DIVs as needed using some javascript (like JQuery)

François
> --
> 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...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3b7c61b7-647e-48c9-907a-3a52dad7c183%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

signature.asc

Dan Gentry

unread,
May 9, 2014, 4:30:10 PM5/9/14
to django...@googlegroups.com
I would setup a data structure keyed off the session ID (or maybe a logged in user ID) that stored the transaction in progress for the user.  As the user went through the pages this data would be used to display what has already been selected and be updated for each screen.

I suppose that one could keep all of the information in the session data area as well.

Mario Gudelj

unread,
May 9, 2014, 7:51:03 PM5/9/14
to django...@googlegroups.com

So, you basically need a shopping cart. Use sessions.

Other option would be to store everything in cookies and use js to manipulate the products.

--

Tom Evans

unread,
May 10, 2014, 11:22:22 AM5/10/14
to django...@googlegroups.com
It has to be client side, unless you fiddle your "next" and "previous"
buttons to submit forms containing the selection from that page (I
wouldn't do that).

If you are targeting older and newer clients, store the ids in a comma
separated list in a cookie.

If you are only targeting newer clients, use HTML 5 local storage.

When the user finally does hit submit, transfer the list of ids from
the cookie/local storage in to a form field, and handle in the form.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages