13

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?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Thordin9
  • 379
  • 1
  • 4
  • 14

3 Answers3

22

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.

Seppo Erviälä
  • 7,160
  • 7
  • 35
  • 40
0

*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
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
0

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) 
rattray
  • 5,174
  • 1
  • 33
  • 27