I'm fairly new to Django and I'm building a multi tenant app. I'm not really sure how to get the logged in user's current tenant in order to use it as a filter in views. Example: Post.objects.filter(tenant=current_tenant)
Example Models:
from django.db import models
class Tenant(models.Model):
name = models.CharField(…)
class CustomUser(AbstractUser):
tenant = models.ForeignKey(Tenant, …)
class Post(models.Model):
user = models.ForeignKey(CustomUser, …)
title = models.CharField(…)
class Comment(models.Model):
post = models.ForeignKey(Post, …)
text = models.CharField(…)
Where should I write the get_current_tenant
function and how should I write it?
Any help would be greatly appreciated.