环境
Python 3.7.7
Django 2.2.16
django-import-export 2.4.0
示例
admin.py
from django.contrib import admin
from import_export.admin import ImportExportModelAdmin, ExportMixin
from import_export.formats import base_formats
class ExportMixinAdmin(ExportMixin, admin.ModelAdmin):
def get_export_formats(self):
formats = (
base_formats.XLSX,
base_formats.CSV,
base_formats.JSON,
base_formats.XLS,
)
return [f for f in formats if f().can_export()]
class Meta:
abstract = True
@admin.register(Task)
class TaskAdmin(ExportMixinAdmin):
pass
参考
stackoverflow.com/questions/45930421/how-to-have-only-csv-xls-xlsx-options-in-django-import-export