如何在django-import-export中仅包含CSV,XLS,XLSX选项? [英] How to have only CSV, XLS, XLSX options in django-import-export?

查看:145
本文介绍了如何在django-import-export中仅包含CSV,XLS,XLSX选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的项目实现了 django-import-export .

I have implemented django-import-export for my project.

默认情况下,它为我提供了导入和导出的许多文件格式选项.

It provides me many file format options by default fro both import and export.

如何将文件格式限制为仅CSV,XLS和XLSX?

How to restrict the file formats to only CSV, XLS and XLSX ?

推荐答案

您可以覆盖ExportMixinget_export_formats()方法:

from import_export.formats import base_formats


class MyAdmin(ExportMixin):
    # your normal stuff
    def get_export_formats(self):
            """
            Returns available export formats.
            """
            formats = (
                  base_formats.CSV,
                  base_formats.XLS,
                  base_formats.XLSX,
                  base_formats.TSV,
                  base_formats.ODS,
                  base_formats.JSON,
                  base_formats.YAML,
                  base_formats.HTML,
            )
            return [f for f in formats if f().can_export()]

这篇关于如何在django-import-export中仅包含CSV,XLS,XLSX选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆