Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin: adding pagination links in list of objects to top

Is it possible to have the pagination links that appear at the bottom of a list of objects in Django's admin interface at the top as well?

Can this be done without changing the admin templates? I suspect not, given the lack of a ModelAdmin option, but thought I'd see if anyone had done this before I dug into the template code.

I really, really don't want to have to copy and paste change_list.html into a new file, just so I can add a pagination line - that'll make changing Django versions painful, since I'll have to check if anything's changed in that file, and re-apply my change.

like image 472
Dominic Rodger Avatar asked Jan 21 '23 04:01

Dominic Rodger


1 Answers

Do not copy change_list.html, instead create a new template that extends it:

{% extends "admin/change_list.html" %}

{% block result_list %}
      {% block pagination %} {{ block.super }} {% endblock %} <!-- pagination -->
      {{ block.super }}  <!-- rest of results list -->
{% endblock %}

Then pass the new template's name to ModelAdmin in change_list_template attribute - doc here.

like image 140
Mariusz Jamro Avatar answered Apr 26 '23 09:04

Mariusz Jamro