Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
django-tables2访问请求.session_Django_Django Views_Django Tables2 - Fatal编程技术网

django-tables2访问请求.session

django-tables2访问请求.session,django,django-views,django-tables2,Django,Django Views,Django Tables2,我正在使用django-tables2显示一些与用户所在商店相关的产品数据。我始终存储一个request.session[“current\u shop\u id”]变量,以选择用户可以查看/编辑的产品 例如,在视图中: def get_queryset(self): return Product.objects.filter(shop_id = self.request.session["current_shop_id"]) 该表使用带有按钮的自定义列: cla

我正在使用
django-tables2
显示一些与用户所在商店相关的产品数据。我始终存储一个
request.session[“current\u shop\u id”]
变量,以选择用户可以查看/编辑的产品

例如,在视图中:

def get_queryset(self):
    return Product.objects.filter(shop_id =  self.request.session["current_shop_id"])
该表使用带有按钮的自定义列:

class ShelfActionColumn(tables2.Column):
    empty_values = list() 
    
    def render(self, value, record): 
        view = f"""<a href="/device_all/{record.serial}">
                        <button class="btn btn-secondary">view</button>
                   </a>"""
        return mark_safe(view)
如果
request.session[“current\u shop\u id”],我想禁用
view
按钮表中的shop.id
,因此用户不能通过错误选择其产品来切换店铺

class ShelfTable(tables2.Table):
    actions = ShelfActionColumn(verbose_name = "",)
        
    class Meta:
        model = ShelfStation
        sequence = ("name", "serial", "shop", "actions")