如何在django中使用Group by子句和filter查询

时间:2022-07-19 15:45:21

I went through a lot of links and sites , but i can't find the solution for my problem anywhere. So at last i came here .

我经历了很多链接和网站,但我无法在任何地方找到我的问题的解决方案。所以最后我来到这里。

My problem is that, I want to use the group by clause with the filter query.

我的问题是,我想使用group by子句和过滤器查询。

i have found this

我找到了这个

How to query as GROUP BY in django?

如何在django中查询GROUP BY?

for objects.all() . But could not find anything for objects.filter()

for objects.all()。但无法找到objects.filter()的任何内容

Here is my query

这是我的查询

query =Kicthen.objects.filter( cabinets='1').query

query.group_by = ['style_id']

results = QuerySet(query=query, model=Kicthen)

But its return nothing.

但它没有回报。

I don't want to use any annotate and distinct with it

我不想使用任何注释和与它不同

1 个解决方案

#1


1  

Use can use raw to make group by http://doughellmann.com/2007/12/using-raw-sql-in-django.html

使用可以使用raw来制作组http://doughellmann.com/2007/12/using-raw-sql-in-django.html

#1


1  

Use can use raw to make group by http://doughellmann.com/2007/12/using-raw-sql-in-django.html

使用可以使用raw来制作组http://doughellmann.com/2007/12/using-raw-sql-in-django.html