2

In our multi-tenant system (using Postgresql), we want to allow different tenants to "associate" with each other, and share some data. So if Tenant A is associated with Tenant B, when showing the shared data, our queries will need to get data from schema A AND schema B.

I've found examples that show how to do so with straight Postgresql code; something like this:

select * from S1.table1
UNION ALL
select * from S2.table1

...though ours would be much more complicated than that. But I've not found anything that explains how to do it with Django's ORM. In other words, how would I do the above with the query syntax we actually use in our site:

queryset = MyTable.objects.filter(client_id__in=clients, status=Status.ACTIVE)
ExTexan
  • 373
  • 2
  • 18
  • Similar question : https://stackoverflow.com/questions/431628/how-can-i-combine-two-or-more-querysets-in-a-django-view But keep in mind it will return a list not a query set... – Shivendra Pratap Kushwaha Feb 11 '22 at 13:10
  • 1
    @Shivendra, Thanks for the link, but that seems to be just about combining two tables. My question is actually about how to specify that I want to pull from two tables in TWO (or more) schemas - and, specifically, what the syntax is for doing so with ORM, not SQL code. – ExTexan Feb 11 '22 at 15:11

0 Answers0