Django add function to "from" clause?
I'm trying to write a Django query that generates the following:
select group_id, cardinality(array_agg(distinct aul))
from report_table, unnest(active_user_list) as aul
group by group_id
Where active_user_list is an array[int] type.
I'm trying to get a count of the unique items in the arrays of all rows that are in a group. The queryset.extra method gets me very close to this, but adds double quotes around unnest(active_user_list) as aul and doesn't work. I created a custom sql function that does work, but I'd prefer to do it in Django if possible.