Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pivot on Union Queryset : Calling QuerySet.distinct() after union() is not supported. #25

Open
Bbillyben opened this issue Oct 27, 2022 · 1 comment

Comments

@Bbillyben
Copy link

Bbillyben commented Oct 27, 2022

Hi there,

I'm trying to get some dashboarded datas on some models, and even between models.

issue description :
When I union 2 queryset of models objects, and then try to pivot with pivot_table, I've got the issue :

django.db.utils.NotSupportedError: Calling QuerySet.distinct() after union() is not supported.

Step to reproduce :

  1. define a model
  2. add some new instances
  3. :
    a=models.MYModel.objects.filter(pk=1)
    b=models.MYModel.objects.filter(pk=2)
    c=a.union(b)
    pivot_table = pivot(c, 'field1', 'field2', 'field3')

=> raise the error above

is there anything I missed ?

infos :
django v4.1.2
python v3.9.2
django-pivot v1.9.0

@martsberger
Copy link
Owner

I looked into this a bit. There are a few things Django doesn't let you do with a union queryset, as you note above, you can't call distinct() on it. You also can't call annotate(), which means the core of how the pivot function works would have to be re-written and I'm not sure it's even possible (depending on what kind of aggregate you want to do) to do that through the ORM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants