In Django, how do I select 100 random records from the database? [duplicate]

Content.objects.all().order_by('?')[:100]

See the order_by docs. Also be aware this approach does not scale well (in fact, it scales really, really badly). See this SO answer for a better way to handle random selection when you have large amounts of data.

Leave a Comment