Z
Z
zipter2020-04-19 21:53:21
Django
zipter, 2020-04-19 21:53:21

Djfngo filter data in alphabetical range?

there are buttons "A-B", "M-F", etc. how to make that when clicking on the button, the data from the database is displayed in the appropriate range.

I'll ask a different question.

def filter_symbol(request):
    f = StartFilter(request.GET, queryset=Staff.objects.filter(Q(name__startswith='А') | Q(name__startswith='Б')
                                                               | Q(name__startswith='В') | Q(name__startswith='Г')))


this is how I managed to display the range (A-D). and this is not correct in any way.
If anyone has experienced this before please let me know how it goes...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Shatalov, 2020-04-20
@netpastor

def filter_symbol(request):
    letter_filter = Q()
    for letter in 'АБВГ':
        letter_filter |= Q(name__startswith=letter)
    f = StartFilter(request.GET, queryset=Staff.objects.filter(letter_filter)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question