xxxxxxxxxx
User.objects.order_by('?') #If you do that in production - you may as well forget about sleep!
will kill the db server on the second day in production
#better approach
from django.db.models.aggregates import Count
from random import randint
class PaintingManager(models.Manager):
def random(self):
count = self.aggregate(count=Count('id'))['count']
random_index = randint(0, count - 1)
return self.all()[random_index]