Matt McCormick Matt McCormick - 1 year ago 83
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.

Answer Source

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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download