Filtering only on Annotations in Django

后端 未结 6 2040
执念已碎
执念已碎 2020-12-13 14:13

Taking the example from: http://docs.djangoproject.com/en/dev/topics/db/aggregation/#filter-and-exclude

Publisher.objects.filter(book__rating__gt=3.0).annota         


        
6条回答
  •  温柔的废话
    2020-12-13 14:37

    You can use the annotation variable in the filter.

    publishers=Publisher.objects.annotate(num_books=Count('book')).filter(num_books__gte=2)
    

提交回复
热议问题