Django - Select-options using for order by

Hello guys now i have a 1 question. I want to let my page visitors can order products by 4 options (ex: order by name asc or name desc) . Here is my html codes:

< select class=“custom-select custom-select-xs” name=‘orderby’>
< option value=“nameaz” selected>Ürün Koduna Göre A-Z< /option>
< option value=“nameza”>Ürün Koduna Göre Z-A< /option>
< option value=“draweraz”>Çekmece Sayısına Göre Artan< /option>
< option value=“drawerza”>Çekmece Sayısına Göre Azalan< /option>
</ select>

and when i searching on the internet i saw a man did in forms.py this and i did too (But i didn’t understand compleatly):

class OrderForm(forms.Form):
Order_CHOICES = (
(‘nameaz’, ‘Urun_Kodu’), (‘nameza’, ‘-Urun_Kodu’),
(‘draweraz’, ‘Cekmece_Sayisi’), (‘drawerza’, ‘-Cekmece_Sayisi’),)
orderby = forms.ChoiceField(choices = Order_CHOICES)

And now i dont know how to do on views.py

But also i’m using the pagination of django like this:

paginator = Paginator(productlist, 9)
page_number = request.GET.get(‘page’,1)
page = paginator.get_page(page_number)

I hope someone can find a solution with working with django pagination system.
Last little question: I also want to let visitors to filter by themself. (ex: i want to see only black products and products who have 2 drawer). Is it possible and solution of my first question and second question is similiar? (I couldn’t find anything when i write django filtering on google, i only see template filters)

This more has to do with applying filters to your query results. See Retrieving specific objects with filters and Field lookups, along with the rest of the information on those two pages.

1 Like

Mr ken as i see you are a good at django. If you know can you give response to my this question:
I’m making a multilangual site and i’m using 7 or 8 if elif endif in every template, like this:

{% if ‘/tr/’ in request.path %} include something
{% elif ‘/en/’ in request.path %} include somethingelse

Am i doing something bad or every multilangual site’s done like this? or do i need to copy every template and change the word’s to second language?

Sorry, I have no experience with the multilingual facilities. I’m guessing there’s some way to do this more properly, but I wouldn’t know what it is.
I’d also suggest that when you have a different question on a different topic, that you open a new conversation on that topic to make it more visible, rather than chaining it on to an existing conversation on a different topic.

1 Like