Mohammadali Kashani
Mohammadali Kashani

Reputation: 11

how to implement sorting in django site

I have a shopping site and I want implement sorting products in my site I know how order_by works but I don't know how to pass arguments through url to check it I use class base view (ListView)

my view:

class ProductList(ListView):
    template_name = 'products/store.html'
    paginate_by = 8

    def get_queryset(self):
        return Product.objects.get_active_products()

I use dropdown (with tag a) for finding witch order user want to sort

for example in amazon when you sort items "&s=price-asc" has added to url that means we sort ascending

Upvotes: 1

Views: 211

Answers (1)

unbrokenguy
unbrokenguy

Reputation: 359

You can use dict with request parameters from self.request.GET in get_queryset(self) method.

Upvotes: 1

Related Questions