bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.46k stars 424 forks source link

Get the tenant/schema that owns a specific object #637

Open tylerecouture opened 4 years ago

tylerecouture commented 4 years ago

If I have an object from a tenant model, is there some sort of reverse lookup I can do to determine which tenant it belongs to?

NotANormalNerd commented 4 years ago

You can lookup which schema currently is being used by your connection by:

from django.db import connection
print(connection.tenant)