Filtering on the count with the Django ORM -


I have a query that basically "counts all items of type X, and returns those items back Which is present more than once, together with their calculations "I have this now:

  Item.objects.annotate (type_count = models.Count (" type ")). Filter (type_count__gt = 1) .order_by ("-type_count")  

but it does not return anything (the count for all objects is 1). Am i doing wrong

Ideally, it should get the following:

  type ---- 1 1 2 3 3 3  

and Return:

  type, calculation ----------- 1 2 3 3  

In Django it is done using the values ​​ to get that area, therefore, it should work:

  Item.objects.values ​​( 'group'). Annotate (type_count = model.count ("type") .Filter (type_count__gt = 1) .order_by ("-type_count")  

Comments