Answer the question
In order to leave comments, you need to log in
How to get repeats in queryset?
I'll give you an example right away. I have a list of ten id's (1,1,2,2,3,3,4,4,4,5). I need for each ID to check a certain checkbox (checked or unchecked) in the model and display the result.
What am I doing:
q = Model.objects.filter(id__in=[1,1,2,2,3,3,4,4,4,5])
no = q.filter(license=False),
yes = q.filter(license=True)
Answer the question
In order to leave comments, you need to log in
Well then something like this:
q = [Model.objects.get(pk=x) for x in [1,1,2,2,3,3,4,4,4,5]]
no = list(filter(lambda x: x.license == False, q))
yes = list(filter(lambda x: x.license == True, q))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question