Hi
On 2/9/07, Brett Parker <[EMAIL PROTECTED]> wrote:
> Err, why not use a random sort as...
>
> Obj.objects.order_by('?')
>
> ref: http://www.djangoproject.com/documentation/db_api/#order-by-fields
Becasue I didn't know it (a good reason, I think).
> Cheers,
Thanks Brett!
Kai
--~--~-
On Fri, Feb 09, 2007 at 03:11:57PM +0100, Kai Kuehne wrote:
>
> Hey!
> I wanted to select all models, but in random order:
>
> random.shuffle(Obj.objects.all())
>
> This doesn't work, error message:
>
> TypeError: object does not support item assignment
Err, why not use a random sort
Sorry, I got it:
all = Obj.objects.all()
newlist = [x for x in all]
random.shuffle(newlist)
Not that beautiful, but it works. :)
Greetings
Kai
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django use
Hey!
I wanted to select all models, but in random order:
random.shuffle(Obj.objects.all())
This doesn't work, error message:
TypeError: object does not support item assignment
Anyony an idea in how to make it?
(It's for a blogroll, if you wonder where it could be used.)
Greetings :)
4 matches
Mail list logo