yes. :-)
On Jan 20, 5:48 pm, Bruce Wade <[email protected]> wrote: > Would this be the best approach: > todays_ids = set(used_ad_ids) > unseen_ads_query = self.db(~self.db.ads.id.belongs(todays_ids)) > unseen_ads_query = unseen_ads_query(self.db.ads.points >= 0) > unseen_ads_query = unseen_ads_query(self.db.ads.viewable == True) > unseen_ads_query = unseen_ads_query(self.db.ads.accepted == True) > *unseen_ads = unseen_ads_query.select(orderby='<random>', > limitby=(0,5))* > > > > > > > > > > On Fri, Jan 20, 2012 at 3:34 PM, Bruce Wade <[email protected]> wrote: > > Hi, > > > I have selected a list of objects from the database, which is working. Now > > I would like to select 5 random rows from the list and ideally only hit the > > database once to get them 5 random rows. > > > todays_ids = set(used_ad_ids) > > unseen_ads_query = self.db(~self.db.ads.id.belongs(todays_ids)) > > unseen_ads_query = unseen_ads_query(self.db.ads.points >= 0) > > unseen_ads_query = unseen_ads_query(self.db.ads.viewable == True) > > unseen_ads_query = unseen_ads_query(self.db.ads.accepted == True) > > unseen_ads = unseen_ads_query.select() > > > # now pull 5 random rows out of the returned rows, each time this > > method is called the random 5 should always be different from the last call. > > # Can this be done before the last select() statement and allow to > > use limit(5) so the database isn't hit so hard if there were 1,000,000 > > results in the select() and I only need 5 random out of the 1,000,000 > > > return unseen_ads > > > Also please let me know if their is a more efficient way to do the above > > query. > > > -- > > -- > > Regards, > > Bruce Wade > >http://ca.linkedin.com/in/brucelwade > >http://www.wadecybertech.com > >http://www.warplydesigned.com > >http://www.fitnessfriendsfinder.com > > -- > -- > Regards, > Bruce > Wadehttp://ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.fitnessfriendsfinder.com

