Dynamic Selector with Django/Jquery

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Dynamic Selector with Django/Jquery

anonymouscodar
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.

Screenshot from 2017-04-15 11-43-55.png (149K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dynamic Selector with Django/Jquery

m712 - Developer

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.

On Apr 15, 2017 7:31 PM, Anonymous Coder <[hidden email]> 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.
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/CA%2B8umNWjgfxZYOodsznfR08KDR745op4Yw7qV3yBK5MZqUcVBw%40mail.gmail.com?utm_medium&#61;email&amp;utm_source&#61;footer">https://groups.google.com/d/msgid/django-users/CA%2B8umNWjgfxZYOodsznfR08KDR745op4Yw7qV3yBK5MZqUcVBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/58f2516e.4d881c0a.8d9c5.67a2SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dynamic Selector with Django/Jquery

Melvyn Sopacua
In reply to this post by anonymouscodar

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

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/4852443.rUL9aSSnB0%40devstation.
For more options, visit https://groups.google.com/d/optout.
Loading...