this won't work, you're doing things across two entire dbs. So you'l have
to implement all the logic in python to execute.
On Thursday, April 20, 2023 at 9:58:20 AM UTC-4 Mạnh ĐỖ wrote:
> 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/99dc653f-ad9e-445a-8d06-310f3351b66dn%40googlegroups.com.