Django Tenants

Does anybody has experience in django-tenants and/ django-tenants-user? I want to have multiple sites for clients with standard users who can just access their site and some superuser who can access all sites.

I don’t see how to archive the second part. I have multiple sites where users can access all other sites. That defeats the purpose.

Hmmm, … reading through the documentation, I would have guessed that if you’ve got the TenantMainMiddleware above the AuthenticationMiddleware, that the AuthenticationMiddleware would pull from the User model for the site. (This implies that you have a separate User table in each site’s schema.)

Since it looks like django-tenants works by adding the site’s schema to the front of the PostgreSQL search path, if a User table exists in the site’s schema, that’s the instance being used. This means that your superuser User object would need to be copied to all the site’s User table.

(This is all conjecture based on what I’m reading in the django-tentants docs. There’s no experience to back this up.)


1 Like

Hi Ken,
thanks for your reply. You can’t imagine how much this helped. I was down a rabbit hole and was going nowhere. My wife really got cranky cause I pondered this problem day and night.
I guess you can related to the feeling when something just isn’t working plus the deadline is drawing near.

So I ended up using the PUBLIC_SCHEMA_URLCONF to create a “portal” where Superusers can create tenants.
When a tenant is created I use with schema_context(tenant.schema_name) and copy the superusers. The copy part was really easy: get the user from the public schema usermodel and then just save the user in the new context.

Thanks Ken!