Unable to get SaaS data for tenant using django-tenants, showing all data not tenant specific data

14 Views Asked by At

I am building a web application using django-tenants and have followed the documentation thoroughly, but still having issues showing data for a tenant specific to its subdomain and schema. Instead, I am getting all the data from the public schema, not the tenant specific schema regardless of the URL I am accessing. tenant.models has my tenant and subdomain models. And then apps are my django apps I want across tenants.

I believe my issue is how I have my shared and tenant apps, but from many different combinations nothing changes on the front end.

tenant.models.py:

class MspCompany(MyBaseModel, TenantMixin):
    company_name = models.CharField(max_length=60)
    industry_type = models.CharField(max_length=68, choices=INDUSTRY_TYPE)
    email = models.EmailField(max_length=150, unique=True)
    owner_name = models.CharField(max_length=60, blank=True, null=True)
    description = models.TextField(blank=True, null=True)
    picture = models.ImageField(upload_to='images/company',blank=True,null=True)
    users = models.ForeignKey(settings.AUTH_USER_MODEL, 
                                     related_name='users',
                                     on_delete=models.CASCADE
                                    )

class Domain(DomainMixin):
    pass

shared apps and tenant apps:

SHARED_APPS = [
    'django_tenants',
    'tenants',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'whitenoise.runserver_nostatic',
    'django.contrib.sites',
    "mathfilters",
    "crispy_forms", # Crispy Forms
    "social_django",
    "django_extensions",
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
    'multiselectfield',
    'phone_field',
    'djstripe',
    'chat',
    'ckeditor',
    'ckeditor_uploader',
    'taggit'
]

TENANT_APPS = [    
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    "dashboards",
    "apps",
    'accounts',
    "layouts",
    "components",
    "pages",
    ]

You will see from the images below, the data is the same regardless of the subdomain I type in. probleu.localhost should be blank as I have just created this new tenant. What am I overlooking?

Public domain url: enter image description here

Tenant subdomain url: enter image description here

0

There are 0 best solutions below