B
B
Bjornie2017-04-11 00:13:27
Django
Bjornie, 2017-04-11 00:13:27

How to select only unique objects from queryset?

My current query returns a list of objects, each of which has a key pair 'day': 1. 'day': 2, and so on. but they are repeated.

<<QuerySet [{'id': 217186, 'day': '1'}, {'id': 217187, 'day': '1'}, {'id': 217188, 'day': '1'}, {'id': 217189, 'day': '1'}, {'id': 217190, 'day': '1'}, {'id': 217191, 'day': '1'}, {'id': 217192, 'day': '1'}, {'id': 217193, 'day': '1'}, {'id': 217194, 'day': '1'}, {'id': 217195, 'day': '2'}, {'id': 217196, 'day': '2'}, {'id': 217197, 'day': '2'}, {'id': 217198, 'day': '2'}, {'id': 217199, 'day': '2'}, {'id': 217200, 'day': '2'}, {'id': 217201, 'day': '2'}, {'id': 217202, 'day': '2'}, {'id': 217203, 'day': '2'}, {'id': 217204, 'day': '3'}, {'id': 217205, 'day': '3'}, '...(remaining elements truncated)...']>

The goal is only to find out which days of the week are present in this queryset. Those. select unique values ​​from duplicate values. Please tell me how to do it in my case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2017-04-11
@Bjornie

as in life - Distinct or Group by according to the situation
in Django, see options here , but in general, master Annotate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question