Filtering only on Annotations in Django

后端 未结 6 2069
执念已碎
执念已碎 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:50

    I just facing this kind of problem. And if my interpreation for the problem and expected solution is correct, this is my working solution:
    Publisher.objects.annotate(num_books=Count('book')).filter(book__rating__gt=3.0) Just swap filter & annotate position. This is done in Django version 1.9

提交回复
热议问题