Filtering on the count with the Django ORM -
Filtering on the count with the Django ORM -
i have query that's "count items of type x, , homecoming items exist more once, along counts". right have this:
item.objects.annotate(type_count=models.count("type")).filter(type_count__gt=1).order_by("-type_count") but returns nil (the count 1 items). doing wrong?
ideally, should following:
type ---- 1 1 2 3 3 3 and return:
type, count ----------- 1 2 3 3
in order count number of occurrences of each type, have grouping type field. in django done using values field. so, should work:
item.objects.values('group').annotate( type_count=models.count("type") ).filter(type_count__gt=1).order_by("-type_count") django orm aggregate
Comments
Post a Comment