Re: pull a random record from the database

2007-11-10 Thread Hani Musallam
One last thought. By writing a wrapper, does this not limit the random book object to teh wrapped view? So, If I wanted to use it elsewhere, (say in the sidebar, or the forums page), I would have to re-write teh code/wrapper? Would it not be easier to make this a method of the model class. I

Re: pull a random record from the database

2007-11-09 Thread James Bennett
On Nov 9, 2007 10:32 PM, Hani <[EMAIL PROTECTED]> wrote: > What I want to do is display 1 random book on the main page. I > currently use a generic view to display a list of books on the main > page but I also want a random book highlighted. (imagine two columns > on the main page, one is the

Re: pull a random record from the database

2007-11-09 Thread Hani
Loren, Kenneth and Joe, Thanks for your response. I'm going to try your code and see. Thanks, Hani On Nov 9, 8:21 pm, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote: > On 10-Nov-07, at 12:56 AM, LorenDavie wrote: > > > import random > > Book.objects.all()[random.randint(0,Book.objects.count()-1]

Re: pull a random record from the database

2007-11-09 Thread Hani
Hi again James, The section speaks to ordering the set randomly. I understand this to mean that the sort would be random. Is this incorrect? What I want to do is display 1 random book on the main page. I currently use a generic view to display a list of books on the main page but I also want a

Re: pull a random record from the database

2007-11-09 Thread Kenneth Gonsalves
On 10-Nov-07, at 12:56 AM, LorenDavie wrote: > import random > Book.objects.all()[random.randint(0,Book.objects.count()-1] Book.objects.order_by('?')[0] -- regards kg http://lawgon.livejournal.com http://nrcfosshelpline.in/web/ --~--~-~--~~~---~--~~ You

Re: pull a random record from the database

2007-11-09 Thread Joe
How about : Book.objects.order_by('?')[:1].get() On Nov 9, 2:26 pm, LorenDavie <[EMAIL PROTECTED]> wrote: > How about this: > > import random > Book.objects.all()[random.randint(0,Book.objects.count()-1] > > On Nov 9, 2:00 pm, Hani <[EMAIL PROTECTED]> wrote: > > > Hi James, > > > I did go

Re: pull a random record from the database

2007-11-09 Thread LorenDavie
How about this: import random Book.objects.all()[random.randint(0,Book.objects.count()-1] On Nov 9, 2:00 pm, Hani <[EMAIL PROTECTED]> wrote: > Hi James, > > I did go through the API documentation but did not find what I wanted. > Please note that I am both a Django and Python newbie so its

Re: pull a random record from the database

2007-11-09 Thread James Bennett
On Nov 9, 2007 1:00 PM, Hani <[EMAIL PROTECTED]> wrote: > I did go through the API documentation but did not find what I wanted. > Please note that I am both a Django and Python newbie so its likely I > did not 'get it'. Would you direct me to the pertinent topic/heading/ > paragraph?

Re: pull a random record from the database

2007-11-09 Thread Hani
Hi James, I did go through the API documentation but did not find what I wanted. Please note that I am both a Django and Python newbie so its likely I did not 'get it'. Would you direct me to the pertinent topic/heading/ paragraph? And I did not take your response as mean. No worries. :) On

Re: pull a random record from the database

2007-11-09 Thread James Bennett
On Nov 9, 2007 12:44 PM, Hani <[EMAIL PROTECTED]> wrote: > What I would like to do is create a method to the model, say > random_id, so that object.random_id will access a random instance. I'm not trying to be mean, but what you should do is read Django's database API documentation, which

pull a random record from the database

2007-11-09 Thread Hani
Hi, I have a model, Books. On the main page of the site, I want to pull and display the details for a random book. What I would like to do is create a method to the model, say random_id, so that object.random_id will access a random instance. Would I define a function in the model definition