I want to use annotate and subquery to join tables.
Table1 in database1 and table2 in database2. But it's not work.
I got the error:

 QuerySet.annotate() received non-expression(s): database1.

the code here:
from django.db.models import Subquery, OuterRef, Count from app1.models 
import Table1 from app2.models import Table2 subquery = Table2.objects.
filter(table1_id=OuterRef('id')).values('table1_id').annotate(count=Count(
'id')).values('count') queryset = 
Table1.objects.annotate(table2_count=Subquery(subquery, 
output_field=models.IntegerField()), using='database1')

Could anyone help me?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5c53820c-ead4-414f-9ecc-0afdc9549e5bn%40googlegroups.com.

Reply via email to