Don’t listen to him. .order_by('?') is the right thing. If you’re not sure,
install django-debug-toolbar. You’ll see that you get "ORDER BY random()".
Also, while .get() will throw an exception if the QuerySet is empty, nothing
else will.
On Mar 18, 2013, at 10:46 PM, Mike Dewhirst wrote:
> O
I am doing this.
featured = Product.objects.filter(is_featured=True,
is_active=True).order_by('?')[:4]
On Tuesday, March 19, 2013 12:03:28 AM UTC-4, Mike Dewhirst wrote:
>
> No really, I want a maximum of ten random records from the database
> (Django 1.4, Postgres 9.1).
>
>
> Looking at t
On 19/03/2013 3:29pm, Christophe Pettus wrote:
On Mar 18, 2013, at 9:03 PM, Mike Dewhirst wrote:
No really, I want a maximum of ten random records from the database
(Django 1.4, Postgres 9.1).
This is a case where the raw SQL interface might be the right answer:
you can just tack an ORDER BY
On Mar 18, 2013, at 9:03 PM, Mike Dewhirst wrote:
> No really, I want a maximum of ten random records from the database (Django
> 1.4, Postgres 9.1).
This is a case where the raw SQL interface might be the right answer: you can
just tack an ORDER BY random() clause onto the query.
--
-- Chris
4 matches
Mail list logo