1
我有兩種型號Product
和Offer
。 Offer
與Product
有關並且包含'price'
字段。 我可以得到最小值: Product.objects.get(pk=1).offer_set.aggregate(Min('price'))
如何統計有多少記錄在現場有最小值? (Django)
但是我怎麼能得到這個值在列中出現多少次?
有我的解決方案: Product.objects.get(pk=1).offer_set.values('price').order_by().annotate(Count('price'))
然後,我可以得到返回的列表
的第一個元素是否有更好的解決辦法?