Before describing the issue, let me briefly explain the architecture of my project. I am building an app that supports multi-tenancy in Django, using a PostgreSQL database. I have decided not to use different schemas for each tenant. Instead, I store all tenant data in the same schema and the same table but distinguish the data with a tenant_id. I have designed the entire database architecture and created all the models.
Problem: I am currently stuck on the view part. When I write the logic, I need to pass the tenant ID every time to fetch the data from the model. Is there a way to pass the tenant ID just once, and have the model automatically filter the data accordingly?
thank you for your support,
but i need the way to implement the logic in view.py i don’t want to pass the “tenant id ” every time in function of views.py , when do query work.
The model could possibly be handling hundreds of requests from different tenants at the same time. There’s no practical way for the model to know which tenant is going to be requested for any individual query.
I’m sorry, I phrased my response very poorly. I meant to say that you need to pass the tenant id from the view to the query with every query being made.
I know that that’s not what you would like to do, but you don’t really have any other good or reliable options.