E
E
Evgeniy Homov2021-12-17 12:37:50
Python
Evgeniy Homov, 2021-12-17 12:37:50

Split Django QS result into separate lists?

There is a Django QS like this:

<QuerySet [<Seats: 1 - 1>, <Seats: 1 - 2>, <Seats: 1 - 3>, <Seats: 1 - 4>, <Seats: 1 - 5>, <Seats: 1 - 6>, <Seats: 1 - 7>, <Seats: 1 - 8>, <Seats: 2 - 
1>, <Seats: 2 - 2>]>

I need to bring this result into a list by the unique values ​​of the series, it should look like this:
filtered_list = 


The model consists of:
row = models.IntegerField()
seat = models.IntegerField()

respectively - Seats: row - seat

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mkone112, 2021-12-17
@0x86

Well the first that comes to mind - to use a cycle. Something like

from collections import defaultdict
res = defaultdict(list)
for q in qs:
    res[q.row].append(q)
res = res.values()

Сергей Протько, 2015-07-19
@Fesor

CODEIGNITER

Судя по характеру вопроса вы только начинаете путь среди всех этих новомодных штуки и фреймворков. Дам вам совет - бегите от кодигнайтера, это зомби который сожрет ваши мозги!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question