“显示全部” Django Admin 中的 200 多个项目

发布于 2024-10-10 09:50:02 字数 242 浏览 0 评论 0 原文

我目前在 django admin 中有一个列表,分为 8 页。

我需要做的是有一个按钮/链接来显示 django admin 中列表的所有项目,即使有超过 200 个项目,同时保持分页。

显示全部链接正是我所需要的,但它仅限于 200 个项目。有什么办法可以改变它吗? (不修改核心)。另外,是否有方法可以根据需要更改 modeladmin 中的 list_per_page

I currently have a listing in django admin that is split across 8 pages.

What I need to do is to have a button/link to display all items of a list in django admin even if there are more than 200 items while keeping the pagination.

Show all link does exactly what I need but it's limited to 200 items. Are there any ways to change it? (without modifying the core). Also, are there ways to change list_per_page in the modeladmin on demand?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半山落雨半山空 2024-10-17 09:50:02

您可以更改管理类上的 list_max_show_alllist_per_page 属性。

class FooAdmin(admin.ModelAdmin):
    list_max_show_all = 500
    list_per_page = 200

适用于 Django 1.4 及更高版本。 请参阅手册。

You can change the list_max_show_all and list_per_page attributes on your admin class.

class FooAdmin(admin.ModelAdmin):
    list_max_show_all = 500
    list_per_page = 200

Works with Django 1.4 and newer. See the manual.

知你几分 2024-10-17 09:50:02

当您说“按需”修改 list_per_page 时,不确定这是否是您正在寻找的内容,但您几乎可以肯定可以查询数据库。这会相当笨重,但根据您的用例,管理员可以登录,修改他们的首选项,然后继续执行任何真正重要的模型。
例如:

#models.py
class PageLength(models.Model):
     page_length = models.IntegerField()

#admin.py

class FooAdmin(admin.ModelAdmin):
     list_per_page = PageLength.objects.get(pk=1) 

Not sure it's what you're looking for when you say "on demand" modification of list_per_page, but you could almost certainly query a database. It'd be rather unwieldy, but depending on your use case, administrators could log in, modify their preference, and then proceed to whatever model actually matters.
For example:

#models.py
class PageLength(models.Model):
     page_length = models.IntegerField()

#admin.py

class FooAdmin(admin.ModelAdmin):
     list_per_page = PageLength.objects.get(pk=1) 
堇年纸鸢 2024-10-17 09:50:02

*如果显示全部链接="nofollow noreferrer">list_max_show_all 值大于或等于总项目数,而如果 list_max_show_all 值小于总项目数,则显示全部链接消失。 *list_max_show_all 默认为 200。

因此,您需要为 list_max_show_all 设置高于 200(默认)的值,以显示显示全部链接来列出所有项目,如下所示您需要设置 list_per_page 列出每个分页更改列表页面上的具体项目数。默认情况下,100 设置为 list_per_page

# "admin.py"

@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    list_max_show_all = 400 # Changes from 200 (Default) to 400  
    list_per_page = 300 # Changes from 100 (Default) to 300

*Show all link appears if list_max_show_all value is more than or equal to total items while Show all link disappears if list_max_show_all value is less than total items. *list_max_show_all is 200 by default.

So, you need to set a higher value than 200 (Default) to list_max_show_all to show Show all link to list all items as shown below and you need to set list_per_page to list the specific number of items on each paginated Change List page. By default, 100 is set to list_per_page.

# "admin.py"

@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    list_max_show_all = 400 # Changes from 200 (Default) to 400  
    list_per_page = 300 # Changes from 100 (Default) to 300
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文