gpt4 book ai didi

python - 如何在 django-tables2 中使用基于类的 View 控制分页?

转载 作者:行者123 更新时间:2023-12-03 20:21:56 24 4
gpt4 key购买 nike

我有一个从 SingleTableView 派生的 View 。

禁用分页的说明围绕使用对 RequestConfig 的调用展开,但是在我看来,我没有实现采用请求参数的函数。

我已经尝试覆盖 View 中的 get_table_pagination() 函数和 table_pagination 属性,但这不起作用。

class DetailBuildView(SingleTableView):
template_name = 'shoppinglist/detailbuild.html'
table_class = BuildLineTable
table_pagination = None
def get_table_pagination(self):
return None

def get_queryset(self):
self.shoppinglist = get_object_or_404(ShoppingList, id=self.kwargs['shoppinglist'])
return BuildLine.objects.filter(shopping_list=self.shoppinglist)

最佳答案

如果你想禁用分页,那么你需要设置table_pagination=False。将其设置为 None 意味着 View 使用默认分页。

class DetailBuildView(SingleTableView):
template_name = 'shoppinglist/detailbuild.html'
table_class = BuildLineTable
table_pagination = False

您可以按如下方式覆盖 get_table_pagination,而不是设置 table_pagination,但这样做没有任何优势。

    def get_table_pagination(self):
return False

关于python - 如何在 django-tables2 中使用基于类的 View 控制分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29557279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com