Skip to content
Advertisement

Tag: django-queryset

Get the index of an element in a queryset

I have a QuerySet, let’s call it qs, which is ordered by some attribute which is irrelevant to this problem. Then I have an object, let’s call it obj. Now I’d like to know at what index obj has in qs, as efficiently as possible. I know that I could use .index() from Python or possibly loop through qs comparing

Advertisement