Filtering only on Annotations in Django

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

    Hm, I think you have to use an extra clause:

    Publisher.objects.extra(select={
        'num_books': 'SELECT COUNT(*) ' + \
                     'FROM _book ' + \
                     'WHERE _book.publisher_id = ' + \
                           '_publisher.id AND ' + \
                           'rating > 3.0'
    })
    

提交回复
热议问题