if bids is ordered by index then you could just return
BID.objects.filter(...).filter(pk__lte=id).count() and that should be
what your after in one step (if I've understood the question
correctly).

--
G

On Mar 7, 7:10 am, Hasan Karahan <[email protected]> wrote:
> Hi,
>
> I'm wondering if there is an efficient way to look-up the index of a given
> object in a query-set? I'm using now the following approach:
>
> def get_index (id):
>
> bids = BID.objects.filter (..)
> obj2idx = dict (zip (bids, xrange (bids.count ()))
>
> bid = BID.objects.get (id=ID)
>
> return obj2idx (bid)
>
> This has a linear time processing.. is there a more efficient way to do it?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to