[Django]-Django queries when Joining the same table on itself

3👍

You should be able to achieve this with a mix of annotate and values

OptEvents \
    .objects \
    .filter(campaign__pk=100) \
    .values("label") \
    .annotate(dupCount=mod‌​els.Count("label")) \
    .order_by("dupCount")

Here’s a good blog post on this by Daniel Roseman

Leave a comment