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

Not able to use annotate #1

Open
manoj-punchh opened this issue Jun 1, 2022 · 3 comments
Open

Not able to use annotate #1

manoj-punchh opened this issue Jun 1, 2022 · 3 comments

Comments

@manoj-punchh
Copy link

Is there any way to use async with annotate or subquery, count etc.?

filter(query).order_by(order_by).values('pname').annotate(pname=F('pname'), counts=Count(
            'plocation'))
@iann838
Copy link
Owner

iann838 commented Jun 1, 2022

@manoj-punchh It should work just like that, what error do you find using it ?

@manoj-punchh
Copy link
Author

Error object AsyncQuerySet can't be used in 'await' expression

Here is how I'm making query

data_list = await Policy.aobjects.prefetch_related('plocation_set')
.filter(query).order_by(order_by)
.values('pname')
.annotate(pos_name=F('pname'), applied_locations=Count(
                'plocation'))
.values('id', 'name', 'status', 'created_at', 'updated_at', 'applied_locations', 'poname').distinct()

@manoj-punchh
Copy link
Author

Ok thanks , Now I get it working after adding eval at the end of the query.

data_list = await Policy.aobjects.prefetch_related('plocation_set')
.filter(query).order_by(order_by)
.values('pname')
.annotate(pos_name=F('pname'), applied_locations=Count(
                'plocation'))
.values('id', 'name', 'status', 'created_at', 'updated_at', 'applied_locations', 'poname').distinct().eval()

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