[Fixed]-Django Filter query set

1👍

First thing u need to know Sort is different than Filter

this the solution
in case u add button in html from his action will be redirect to your view named product_list

<button type="submit" name="sortByName"></button>

In your view

After this line
products = products.filter(category=category)

Add this

if 'sortByName' in request.GET:
    products=products.order_by('-name')

and u can reach your goal
Hope this help u
Also keep in touch if u have any inquiry
Thanks

Leave a comment