如何对“更改列表”进行分页Django 管理页面?
在下面的 admin.py
中,所有项目仅显示在 Django 管理中的一个 更改列表 页面上:
admin.py
:
from cliente.models import Cliente
from django.contrib import admin
class ClienteAdmin(admin.ModelAdmin):
list_display = ('nome','bairro','endereco','telefone')
list_filter = ('bairro',)
ordering = ('nome',)
search_fields = ('endereco',)
pass
admin.site.register(Cliente,ClienteAdmin)
现在,我想要对更改列表页面进行分页,以显示每个更改列表页面上的具体项目数。那么,我该怎么做呢?
With my admin.py
below, all items are shown on only one Change List page in Django admin:
admin.py
:
from cliente.models import Cliente
from django.contrib import admin
class ClienteAdmin(admin.ModelAdmin):
list_display = ('nome','bairro','endereco','telefone')
list_filter = ('bairro',)
ordering = ('nome',)
search_fields = ('endereco',)
pass
admin.site.register(Cliente,ClienteAdmin)
Now, I want to paginate Change List page to show the specific number of items on each Change List page. So, how can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这里我以每页10条记录为例,大家可以根据自己的需求进行更改:
Here I take the example of 10 records per page, you can change according to your requirement:
您可以设置 list_per_page 列出每个分页更改列表页面上的具体项目数。默认情况下,
100
设置为list_per_page
。并且,您还可以设置 list_max_show_all 显示或隐藏每个分页更改列表页面上的显示全部链接。默认情况下,
200
设置为list_max_show_all
。 *如果list_max_show_all
值大于或等于总项目数,则显示显示全部链接,而如果list_max_show_all
则消失,则显示全部链接消失> 价值小于物品总数。例如,下面有
Person
模型:并且,下面有
Person
admin:然后,列出所有
7
人,如下所示:< a href="https://i.sstatic.net/Hi5FV.png" rel="nofollow noreferrer">
现在,我将
list_per_page = 4
设置为Person
admin ,如下所示:然后,
4
个人会列在第一页如下所示:并且,第二页上列出了
3
人,如下所示:接下来,我单击 显示全部链接如下所示:
然后,所有
7
个人如下所示:接下来,我设置
list_max_show_all = 6
到Person
admin,如下所示:然后,显示全部链接消失,如下所示,因为
list_max_show_all
值6
小于总人数7
:< img src="https://i.sstatic.net/AokI9.png" alt="在此处输入图像描述">
You can set list_per_page to list the specific number of items on each paginated Change List page. By default,
100
is set tolist_per_page
.And, you can also set list_max_show_all to show or hide Show all link on each paginated Change List page. By default,
200
is set tolist_max_show_all
. *Show all link appears iflist_max_show_all
value is more than or equal to total items while Show all link disappears iflist_max_show_all
value is less than total items.For example, there is
Person
model below:And, there is
Person
admin below:Then, all
7
persons are listed as shown below:Now, I set
list_per_page = 4
toPerson
admin as shown below:Then,
4
persons are listed on the 1st page as shown below:And,
3
persons are listed on the 2nd page as shown below:Next, I click on Show all link as shown below:
Then, all
7
persons are listed as shown below:Next, I set
list_max_show_all = 6
toPerson
admin as shown below:Then, Show all link disappears as shown below because
list_max_show_all
value6
is less than the total persons7
:请参阅 ModelAdmin.list_per_page 。默认值为
100
,但您可以将其设置为更低的值。See ModelAdmin.list_per_page. The default is
100
, but you can set it to a lower value.这里我以每页5条记录为例,您可以根据自己的要求进行更改:
Here I take example of 5 records per page, you can change according to your requirement: