django - Django ListView 派生类忽略 paginate_by 字段
问题描述
我正在使用 Django 3.2
我正在使用 OOP 来保持我的代码干燥。我有一个基类 Foo(它派生自 ListView),并且我在该类中设置公共属性。
然后我有两个 Foo 的特化——我希望知道paginate_by
成员变量——但是,子类似乎忽略了我设置的变量paginate_by
,因为它没有效果。
这是我的代码:
class UserFooList(LoginRequiredMixin, ListView):
http_method_names = ['post']
paginate_by = 2
def post(self, request, *args, **kwargs):
# some processing logic
return render(request, '/path/to/Foo_list.html', context=context, status=status_code)
class UserApprovedFooList(UserFooList):
def get_queryset(self):
return Foo.objects.prefetch_related().filter(/* query criteria one */)
class UserFoosInModerationQueueList(UserFooList):
def get_queryset(self):
return Foo.objects.prefetch_related().filter(/* query criteria two */)
为什么该paginate_by
字段被UserApprovedFooList
and UserFoosInModerationQueueList
- 忽略,我该如何解决?
解决方案
推荐阅读
- java - 如何在 Spring MVC 中设计 API?
- python - 如何从带有字符串的列表中创建子列表?
- php - 警告:尝试访问 C 中 null 类型值的数组偏移量:
- python - 尝试使用 webbrowser 库搜索特殊字符不起作用
- linux - 如何发现 (RT)NETLINK 套接字连接到的网络命名空间?
- reactjs - 在 API 内的嵌套对象中达到价值
- flutter - Dart - 子类是否隐式继承 const 构造函数?
- c - “void *”类型的值不能分配给“link”的空类型。'=': 无法从 'void *' 转换为 'link'
- java - Unchecked Cast 警告 - 显示类型参数但不显示具体类型?
- ruby-on-rails - 带有 webpack 的数据表按钮不起作用