Re: QuerySets - Reverse Look-Up for Index

2010-03-09 Thread Calaganne
Although it works in my interactive environment.. it does not work in my actual script.. ?? On Mar 9, 7:02 pm, Calaganne wrote: > Hey, > > thanx for the reply! No, the bid is *not* ordered randomly, but you > know what, your solution works anyway! ;) Test this and

Re: QuerySets - Reverse Look-Up for Index

2010-03-09 Thread Calaganne
Hey, thanx for the reply! No, the bid is *not* ordered randomly, but you know what, your solution works anyway! ;) Test this and you'll notice that it works.. (still haven't figured out why!): * bs = BID.objects.all () * idx=81; bid=bs[idx]; * bs.order_by ('?').filter (pk__lt=bid.id).count ()

Re: QuerySets - Reverse Look-Up for Index

2010-03-07 Thread greatlemer
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 wrote: > Hi, > > I'm wondering

QuerySets - Reverse Look-Up for Index

2010-03-06 Thread Hasan Karahan
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)