2

I have a problem with django import-export tool. Simmilat to the one described in This topic. Problem is there is no solution for the problem posted there and I need it badly. Buttons for import/export in my admin panel do not show up. Did change the order of declaration, run collectstatic, restarted server ...

I could use your help django masters.

 from django.contrib import admin
    #from actions import export_to_csv
    from import_export import resources
    from import_export.admin import ImportExportModelAdmin, ImportExportMixin, ImportMixin, ExportActionModelAdmin, ImportExportActionModelAdmin
    from .models import Library
    from datetime import datetime
    from django import forms
    from redactor.widgets import RedactorEditor

     # registered models

    class LibraryResource(resources.ModelResource):

        class Meta:
            model = Library

    class LibraryAdmin(ImportExportModelAdmin, admin.ModelAdmin):
        resource_class = LibraryResource

        list_display = ...
        list_display_links = ...
        search_fields =...
        list_filter = ...


        def name(self, obj):
            return obj.library.name
            name.admin_order_field  = 'name'  #Allows column order sorting
            name.short_description = 'Biblioteka'
Community
  • 1
  • 1
Jan Mejor
  • 141
  • 3
  • 15

3 Answers3

2

Remove , admin.ModelAdmin from this line and it should start working: class LibraryAdmin(ImportExportModelAdmin, admin.ModelAdmin):

Sachiv Paruchuri
  • 414
  • 4
  • 11
  • Gosh it took me long to confirm this. It works. I guess problem was in missconfigured static files on top of that error. Plus ... I broke my server on the way. Noob my. Thank you for the answer! – Jan Mejor Apr 18 '17 at 22:14
1
  1. After installing the django-import-export package using:

    pip install django-import-export

  2. Within the settings.py file, add 'import_export' to the list of installed apps:

    INSTALLED_APPS = [ ... 'import_export' ... ]

  3. Within the admin.py file, here is how to use the import_export package:

    from django.contrib import admin

    from import_export.admin import ImportExportModelAdmin

    from .models import Bot

    admin.site.register(Bot, ImportExportModelAdmin)

codedbychavez
  • 193
  • 4
  • 6
0

In my case, I was overriding Django admin list template:

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

{% block object-tools-items %}
  {{ block.super }}

  <Code>
{% endblock %}

But in order for import_export buttons to appear, you need to override their template, so the first line should be:

{% extends "admin/import_export/change_list_import_export.html" %}
Alvaro Rodriguez Scelza
  • 3,643
  • 2
  • 32
  • 47