Dynamic Selector with Django/Jquery

23 views
Skip to first unread message

Anonymous Coder

unread,
Apr 15, 2017, 12:32:16 PM4/15/17
to django...@googlegroups.com
I need to filter lists of items to be displayed upon user selection in my list view.
For instance if user selects 12 it should show only 12 products per page and so on.
My Django view has vairble items like below:

items=Items.objects.all() 
Now I need to get products as per user selection how would i do that?

<form>
<span>Show:</span>
<select class="orderby number" name="page_size">
                                               <option value="9" selected="selected">9</option>
                                               <option value="12">12</option>
                                               <option value="24">24</option>
                                               <option value="36">36</option>
                                               <option value="48">48</option>
                                               <option value="60">60</option>
                                               <option value="90">90</option>
                                               <option value="100">100</option>
</select>
</form>


Screenshot is attached. Please advise.
Screenshot from 2017-04-15 11-43-55.png

m712 - Developer

unread,
Apr 15, 2017, 1:00:54 PM4/15/17
to Anonymous Coder, django...@googlegroups.com

You can create a URL in your application to which your AJAX code will send the details and the amount of items it wants and your application will return the items in JSON format. Take a look at https://docs.djangoproject.com/en/1.11/topics/db/queries/ to learn about how to filter and limit your queries to your need.

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B8umNWjgfxZYOodsznfR08KDR745op4Yw7qV3yBK5MZqUcVBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Melvyn Sopacua

unread,
Apr 20, 2017, 8:14:28 AM4/20/17
to django...@googlegroups.com

On Saturday 15 April 2017 17:31:50 Anonymous Coder wrote:

 

> I need to filter lists of items to be displayed upon user selection in

> my list view.

> For instance if user selects 12 it should show only 12 products per

> page and so on.

 

For this specific issue:

https://docs.djangoproject.com/en/1.11/topics/pagination/

 

And quite easy to do with django.views.generic.ListView.

 

> My Django view has vairble items like below:

>

> items=Items.objects.all()

> Now I need to get products as per user selection how would i do that?

>

> <form>

> <span>Show:</span>

> <select class="orderby number" name="page_size">

 

Add onchange="this.form.submit()".

And tie page_size to the Paginator (paginate_by attribute on ListView) through urls.py.

 

If you need more dynamic filtering (sort order / color filter etc), you

may want to look at one of these:

 

https://djangopackages.org/grids/g/filters/

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages