Я вижу противоречивый упорядоченный результат, как показано ниже.
# filter_queryset / get_queryset is standard DRF method
# I don't do any customization for those methods
delivery_groups = self.filter_queryset(self.get_queryset())
delivery_groups = delivery_groups.filter(
primary_product=product_id
)
delivery_groups = delivery_groups.order_by('-event_winner_condition_met', 'order__user_id')
page = self.paginate_queryset(delivery_groups)
# DeliveryGroup = Foo
class DeliveryGroup(models.Model):
event_winner_condition_met = models.BooleanField(default=False, db_index=True)
order = models.ForeignKey('order.Order', related_name='groups', editable=False, on_delete=models.CASCADE)
# Order = Bar
class Order(models.Model):
user = models.ForeignKey(
settings.AUTH_USER_MODEL, blank=True, null=True, related_name='orders',
verbose_name=pgettext_lazy('Order field', 'user'), on_delete=models.PROTECT)
# whole delivery_groups (printing id only)
[12951, 12941, 12943, 12944, 12945, 12940, 12954, 12946, 12948, 12947, 12953, 12956, 12952, 12942, 12950, 12949, 12955, 11245, 11247, 10399, 10900, 11452, 11\
455, 11453, 9230, 9344, 11463, 11462, 11495, 10717, 9164, 9159, 9391, 9901, 11456, 11454, 11450, 9191, 10870, 10545, 11240, 11685, 11683, 11681, 11697, 11699\
, 11702, 11703, 11704, 11713, 11714, 11715, 11716, 11717, 11718, 11720, 11721, 11695, 11693, 11692, 11690, 11689, 11688, 11687, 11686, 11751, 11754, 11752, 1\
1696, 11694, 11744, 11753, 11755, 11745, 11705, 11698, 11691, 11684, 11682, 11748, 11423, 11749, 11750, 11722, 11723, 11700, 11719, 11701]
page = self.paginate_queryset(delivery_groups). # DRF PageNumberPagination
# first page (id only)
[12949, 12950, 12955, 12951, 12943, 12940, 12944, 12941, 12945, 12942]
Q1. почему первая страница отличается от 10 целых foos
# second page
[12943, 12955, 12940, 12949, 12944, 12951, 12941, 11245, 11247, 10399]
Q2. Более того, 12949 дублируется, тогда как у целого foos
нет дубликатов
Ниже та же информация, только в сеансе pdb
(Pdb) [e.id for e in self.object_list[bottom:top]]
[e.id for e in self.object_list[bottom:top]]
[12949, 12950, 12955, 12951, 12943, 12940, 12944, 12941, 12945, 12942]
(Pdb) [e.id for e in self.object_list]
[e.id for e in self.object_list]
[12951, 12941, 12943, 12944, 12945, 12940, 12954, 12946, 12948, 12947, 12953, 12956, 12952, 12942, 12950, 12949, 12955, 11245, 11247, 10399, 10900, 11452, 1\
1455, 11453, 9230, 9344, 11463, 11462, 11495, 10717, 9164, 9159, 9391, 9901, 11456, 11454, 11450, 9191, 10870, 10545, 11240, 11685, 11683, 11681, 11697, 116\
99, 11702, 11703, 11704, 11713, 11714, 11715, 11716, 11717, 11718, 11720, 11721, 11695, 11693, 11692, 11690, 11689, 11688, 11687, 11686, 11751, 11754, 11752\
, 11696, 11694, 11744, 11753, 11755, 11745, 11705, 11698, 11691, 11684, 11682, 11748, 11423, 11749, 11750, 11722, 11723, 11700, 11719, 11701]
(Pdb) bottom
bottom
0
(Pdb) top
top
10