简体   繁体   English

如何禁用 django 管理分页?

[英]How disable django admin pagination?

I need turn off django admin pagination.我需要关闭 django 管理分页。 I use mttp in django and I need disable pagination on some admin module.我在 django 中使用 mttp,我需要在某些管理模块上禁用分页。

How I can do it?我该怎么做?
Or how I can make pagination only by parents?或者我如何只能由父母进行分页?

The number of items per page is determined by ModelAdmin.list_per_page .每页的项目数由ModelAdmin.list_per_page决定。

As @codingjoe's comment suggests, setting this to sys.maxsize is very likely to suffice.正如@codingjoe 的评论所暗示的那样,将其设置为sys.maxsize很可能就足够了。

import sys

class PartAdmin(admin.ModelAdmin):
    list_per_page = sys.maxsize

@SpiRail's answer isn't far off, but it's not right to do a DB query at module import time. @SpiRail 的答案并不遥远,但在模块导入时进行数据库查询是不对的。 Also, list_max_show_all will not be required, because there will be no "show all" link when all items are already shown.此外,也不需要list_max_show_all ,因为当所有项目都已显示时,将没有“全部显示”链接。

If you're using Django 1.8 (the newest version), there is a new setting on the ModelAdmin class called show_full_result_count that I believe will do what you're looking for.如果您使用的是 Django 1.8(最新版本),ModelAdmin 类中有一个名为show_full_result_count的新设置,我相信它show_full_result_count您的需求。 You can set it to false and it will disable the pagination on the Django admin view.您可以将其设置为 false,它将禁用 Django 管理视图上的分页。

Reference: https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.show_full_result_count参考: https : //docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.show_full_result_count

I do this in order to put everything on one page:我这样做是为了将所有内容都放在一页上:

class PartAdmin(admin.ModelAdmin):
    list_per_page = Part.objects.all().count()
    list_max_show_all = list_per_page

It just counts all the parts (my model is called "Part") and then makes that the max number per page.它只是计算所有零件(我的模型称为“零件”),然后将其设为每页的最大数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM