Django Admin Using Django Reversion and Django-Import-Export

I am trying to enable Django Reversion and Django-Import-Export for the same model ... Not sure if my logic is correct or should I use multiple admin.py files etc.

I tried the following, but this allows Django Reversion to work if I switch them around Import Export Works. It would be great if I could turn on both modes at the same time.

class MyModelAdmin(reversion.VersionAdmin, ImportExportModelAdmin): pass 

I looked at readthedocs for both projects, but I still lost.

http://django-reversion.readthedocs.org/en/latest/admin.html#admin https://django-import-export.readthedocs.org/en/latest/getting_started.html

Cheers xc0m

+7
python django admin django-reversion
source share
3 answers

I ran into the same problem as me, fixed it by expanding the admin_django admin template and adding links through this example below.

 ***change_list.html**** {% extends "admin/change_list.html" %} {% load i18n %} {% block object-tools %} {% if has_add_permission %} <ul class="object-tools "> {% block object-tools-items %} {% if not is_popup %} <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> <li><a href="{{recoverlist_url}}" class="recoverlink">{% blocktrans with cl.opts.verbose_name_plural|escape as name %}Recover deleted {{name}}{% endblocktrans %}</a></li> {% endif %} <li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}</a></li> {% endblock %} </ul> {% endif %} {% endblock %} ***admin.py*** class MyAdmin(ImportExportMixin, MyModelAdmin): change_list_template = "change_list.html" resource_class = MyResource 

Hope this helps you.

+4
source share

I did not do this with Reversion, but I think you want to use ImportExportMixin:

 from import_export.admin import ImportExportMixin class MyModelAdmin(ImportExportMixin, reversion.VersionAdmin): pass 

How I use it with another subclass and it works great.

+1
source share

Final result:

import export recover deleted links

Inspired by @Aidan Doherty's answer , I created a new class, which is a combination of subclasses of VersionAdmin , ImportMixin , ExportMixin , which extends the change_list_template user interface.

Here's what it looks like:

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 %} 

Thus, I can use it as follows:

 class SiteAdmin(ImportExportVersionModelAdmin): pass admin.site.register(Site, SiteAdmin) 

It is directly inspired by import_export admin.py ImportExportMixin and its change_list_import_export.html , combined with a reversal pattern

Note. You can apply this solution to several subclasses :)

+1
source share

All Articles