Matt McCormick Matt McCormick - 10 months ago 39
Python Question

How to get two random records with Django

How do I get two distinct random records using Django? I've seen questions about how to get one but I need to get two random records and they must differ.


If you specify the random operator in the ORM I'm pretty sure it will give you two distinct random results won't it?

MyModel.objects.order_by('?')[:2] # 2 random results.