Django Admin "Export selected" button not showing in Django Admin

42 views Asked by At

I'm trying to enable the "Export selected" button in the Django admin for users to download data as an Excel sheet. I'm using django-import-export but the button isn't appearing.

Here's what I've done: Installed django-import-export (pip install django-import-export).

Trial 1:

class UserAdmin(ImportExportModelAdmin):
    list_display = ('username', 'email'....)

admin.site.unregister(User)
admin.site.register(User, ImportExportModelAdmin)

Trial 2:

class UserAdmin(ExportMixin, admin.ModelAdmin):
    list_display = ('username', 'email'.....)
admin.site.unregister(User)
admin.site.register(User, UserAdmin)

Restarted the development server.

the django-import-export is in INSTALLED_APPS in settings.py

Expected behavior: The "Export selected" button should appear in the Django admin user list view.

Actual behavior: The button is not displayed.

My Question: Why the button is not showing and how can I fix it.

Any suggestions or insights into why the button might not be showing would be greatly appreciated.

1

There are 1 answers

0
Matthew Hegarty On BEST ANSWER

Here is how I enabled using the example app.

  1. Use django-import-export v4.

  2. Go to the 'Category' model instance and add some new categories.

  3. You can now select and export:

enter image description here

To enable this, simply subclass ExportActionModelAdmin (refer to example code):

class CategoryAdmin(ExportActionModelAdmin):
    pass

admin.site.register(Category, CategoryAdmin)