[[+content_image]]
A
A
Artem Shishkov2019-09-11 20:23:27
Django
Artem Shishkov, 2019-09-11 20:23:27

Sorting in Django?

Here I have:

books = books.filter(genre__title=value).order_by('title')

And how to make an array of books in the following form: [['A', [book1, book2, ...], ['B', [book1, book2, ...]], ...]
That is, the letter and together with her all the books that begin with her ...

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
Artem Shishkov, 2019-09-11
@Combot

I was able to figure it out in a more or less adequate way:

Books = books.filter(genre__title=filt).order_by('title')
books = []
for char in "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЭЮЯ":
    books.append([char, Books.filter(title__startswith=char)])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question