Final result:
Inspired from @Aidan Doherty's answer, I created a new class that is a combination of VersionAdmin
, ImportMixin
, ExportMixin
subclasses which extends a custom change_list_template
.
Here's how it looks:
ImportExportVersionModelAdmin.py
:
from import_export.admin import ImportMixin, ExportMixin
from reversion.admin import VersionAdmin
class ImportExportVersionModelAdmin(ImportMixin, ExportMixin, VersionAdmin):
"""
Import, export and Version admin.
Fixes missing link in change_list admin view :)
"""
#: template for change_list view
change_list_template = 'change_list_import_export_version.html'
templates/change_list_import_export_version.html
:
{% extends "admin/import_export/change_list.html" %}
{% load i18n admin_urls %}
{% block object-tools-items %}
<li><a href="import/" class="import_link">{% trans "Import" %}</a></li>
<li><a href="export/{{ cl.get_query_string }}" class="export_link">{% trans "Export" %}</a></li>
{% if not is_popup and has_add_permission and has_change_permission %}
<li><a href="{% url opts|admin_urlname:'recoverlist' %}" class="recoverlink">{% blocktrans with cl.opts.verbose_name_plural|escape as name %}Recover deleted {{name}}{% endblocktrans %}</a></li>
{% endif %}
{{ block.super }}
{% endblock %}
This way I can use it like this:
class SiteAdmin(ImportExportVersionModelAdmin):
pass
admin.site.register(Site, SiteAdmin)
It's directly inspired from import_export's admin.py ImportExportMixin and its change_list_import_export.html template, combined with reversion's template
Note: You can apply this solution to multiple subclasses :)
<ul class="object-tools">
to<ul class="grp-object-tools">
and it keeps everything pretty! Hope this helps someone in the future! – Desta