In models.py I have defined:
class Order(models.Model):
...
class Operation(models.Model):
order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name="operations")
...
I have a queryset of orders where the first order has two operations.
orders = order.annotate(mycount=Count('operations'))
print(orders[0].operations.count())
print(orders[0].mycount)
The previous piece of code returns:
2
1
Hence orders.filter(mycount__gte=2) erroneously returns an empty set.
I can see from old posts that this was already a problem in the past, and that it seems like it got fixed as the forum discussions are old (here for example) .