D
D
DoggoTheKing2018-02-22 13:31:33
Django
DoggoTheKing, 2018-02-22 13:31:33

How to shuffle a QuerySet in Django?

How to randomize a queryset consisting of posts?
upd: The database consists of 8k+ heavily tagged posts

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2018-02-22
@DoggoTheKing

https://docs.djangoproject.com/en/2.0/ref/models/q...
Note: order_by('?')queries may be expensive and slow, depending on the database backend you're using.

S
Stepan Krapivin, 2018-02-22
@xevin

BlogPost.objects.filter(is_public=True).order_by('?')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question