I filtered by entering a list with this query : listobj = Obj.objects.filter(name__in=listname)
However, when it returns the result, the listname doesn't have the same order as before. It's ordered by id. I would like to know if there's a way to avoid this please?
Asked
Active
Viewed 43 times
0

L. Ng
- 19
- 3
-
Exactly what you want? Please share more details. You want to order as per your listname – NIKHIL RANE Jul 21 '16 at 09:28
-
I want that the order of listname remains the same. – L. Ng Jul 21 '16 at 09:30
-
the list ```listname``` change or ```listobj``` has not the same order as ```listname```? – Bestasttung Jul 21 '16 at 09:32
-
ah yes it is listobj who doesn't have the same order as listname. sorry. no it is not ordered alphabetically. i think it is because i printed the id and it was ordered – L. Ng Jul 21 '16 at 09:33
-
I'm going to try it ! Thanks ! – L. Ng Jul 21 '16 at 09:39
-
`Obj.objects.filter(name__in=listname).order_by('name')`. Is this what you want? – Moinuddin Quadri Jul 21 '16 at 09:39
-
No it is not, the list is not ordered by name. Thanks for the answer though ! – L. Ng Jul 21 '16 at 09:41
-
1@Selcuk It worked ! Thanks a lot !! Have a good day ! – L. Ng Jul 21 '16 at 09:50