I have a query that basically "counts all elements of type X and returns elements that exist more than once, together with their values." Right now I have this:
Item.objects.annotate(type_count=models.Count("type")).filter(type_count__gt=1).order_by("-type_count")
but it returns nothing (the number is 1 for all elements). What am I doing wrong?
Ideally, he should get the following:
Type ---- 1 1 2 3 3 3
and return:
Type, Count
django orm aggregate
Stavros korokithakis
source share