I am working on a multitenant Django application using django-tenants library. Getting the current tenant object can be done through one of the two ways:
- This can be used anywhere:
from django.db import connection
tenant = connection.tenant
- This can be used in views.py only where the
requestobject is accessible:
tenant = request.tenant
So, why we have it added to request while it is globally accessible on the connection object?
demo.localhostyou're request belongs to demo tenant.Using request tenant you can set db connection to specific tenant.