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 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 Nov 9, 1:46 pm, "James Bennett" <[EMAIL PROTECTED]> wrote:
>
> > > 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 explains precisely how to accomplish
> > > this.
>
> > > --
> > > "Bureaucrat Conrad, you are technically correct -- the best kind of 
> > > correct."


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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