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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -