首页 > 解决方案 > 如何在我的模板中显示租户模式名称 - django?

问题描述

我正在尝试在我的一个表数据中返回租户模式名称,并且我正在使用django-tenant这就是我想要实现的目标

class Vistor(models.Model):
    admin = models.ForeignKey(User,on_delete=models.PROTECT,default=1)
    full_name = models.CharField(max_length=150)


@login_required
def daily_vistors_detail_html(request,day):
    lists = BookingVisitor.objects.annotate(day=TruncDay('date')).filter(day=day).order_by('-pk')
    context = {
        'lists':lists
    }

有时我必须用它的租户域返回数据!

    <table class="w-full text-center table-auto display nowrap" style="width:100%" id="vistors">
        <thead>
          <tr>
            <th class="p-2 text-xs text-white bglightpurple md:text-base">{% trans "admin" %}</th>
            <th class="p-2 text-xs text-white bglightpurple md:text-base">{% trans "full name" %}</th>
            <th class="p-2 text-xs text-white bglightpurple md:text-base">{% trans "tenant name" %}</th>
          </tr>
        </thead>

        <tbody id="list_vistors_daily" class="w-full">
            
            {% for i in lists %}
            <tr>
                <td class="p-2 text-xs border border-purple-900 md:text-base textpurple">{{i.admin}}</td>
                <td class="p-2 text-xs border border-purple-900 md:text-base textpurple">{{i.visitor.full_name}}</td>
        <td class="p-2 text-xs border border-purple-900 md:text-base textpurple">{{tenant name}}</td><!-- this is should return the current tenant name -->
            

有没有办法从视图中返回当前租户名称?!提前谢谢你

标签: djangomulti-tenant

解决方案


推荐阅读