Is there a way to select a list of group by columns? The aggregation methods seem only apply to a single model but I want to use fields from different models to group by.
select org.id as organization_id, cat."catId",
max(cat."nameDisplay") as nameDisplay,
count(depItem.id) as itemCount
from communitynetwork_listcategory as cat
inner join communitynetwork_listitem as li on
li.category_id = cat."catId"
inner join communitynetwork_organizationdepartmentitem as depItem on
inner join communitynetwork_organizationdepartment as dep on
dep.id = depItem.department_id inner join communitynetwork_organization as org on
org.id = dep.organization_id and org.active = True
or cat."nameDisplay" like '%service%'
This is what I tried to do with a QuerySet that didn't work:
OrganizationDepartmentItem.objects.filter(department__organization__active=True
).filter(Q(item__category__name=searchValue) | Q(item__category__nameDisplay=searchValue)
).order_by('department__organization', 'department__name', 'item__category__order'
).values('department__organization', 'department', 'item__category'
).aggregate(Max('item__category__name'), Max('item__category__nameDisplay'), Count('item'))