LoginSignup
6
6

More than 5 years have passed since last update.

Django、QuerySetでgroup byする方法

Last updated at Posted at 2016-05-11

DjangoのORMでgroup byは"annotate"を使ってるみたいですが、うまくいかなかったので、"QuerySet"使いました。

from django.db.models.query import QuerySet

query = cls.objects.filter(id=id, status=1).query
query.group_by = ['user_id']
result = QuerySet(query=query, model=cls)

以上です。

6
6
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6