[Answer]-Django related _set with order_by showing duplicates

1👍

I don’t know why do you receive duplicate results, because i don’t see nothing unnatural in your code.
In case if you want just to receive a list of cars id (without duplicates), you can change your for cycle in this way:

cars_id = []                 # creating empty list for cars id with duplicates 
for car in cars:             # for cycle 
    cars_id.append(car.id)   # appends numbers 3, 3, 3, 5 to our list
cars_id = list(set(cars_id)) # making list with unique values using built-in function set()

So after you’ll have something like this:

>>> cars_id
... [3, 5]

Leave a comment