From 366d66d43c92480a911ad35715f4ddd5d7a7bb5b Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 26 Nov 2020 18:26:19 +0900 Subject: [PATCH] Deduplicate data on randomized order option, fix #933, fix #1026 --- app/api/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/api/views.py b/app/api/views.py index bd1c8bfe..394a4fc4 100644 --- a/app/api/views.py +++ b/app/api/views.py @@ -1,5 +1,7 @@ import collections import json +import random + from django.conf import settings from django.contrib.auth.models import User from django.db import transaction @@ -171,7 +173,9 @@ class DocumentList(generics.ListCreateAPIView): queryset = project.documents if project.randomize_document_order: - queryset = queryset.annotate(sort_id=F('id') % self.request.user.id).order_by('sort_id') + random.seed(self.request.user.id) + value = random.randrange(2, 20) + queryset = queryset.annotate(sort_id=F('id') % value).order_by('sort_id', 'id') else: queryset = queryset.order_by('id')