Django 导入导出排除不起作用

Django import-export exclude not working

我一直在使用 Django 导入导出,这样我就可以从我的数据库中获取 csv 文件。这些 csv 文件有一些不相关的字段,因为在将项目放入数据库时​​它们会更改,因此我不希望它们出现在 table 中。

我已经按照导入导出文档进行操作,但似乎无法正确排除这些字段。在我的 admin.py 文件中我有:

from import_export import resources
from import_export.admin import ImportExportModelAdmin

class ArtAdmin(ImportExportModelAdmin):
    list_display = ['id', 'name', 'category', 'type', 'agent', 'authenticate', ]
    search_fields = ('name', 'category', 'artist', 'id', 'authenticate', )
    list_filter = ["authenticate"]
    actions = [approve_art, reject_art]

class ArtResource(resources.ModelResource):

    class Meta:
        model = Art
        exclude = ('authenticate', )

当我进入 python manage.py shell 并让它打印出 csv 时,它是我期望的样子,但是当我使用 python manage.py 运行服务器然后导出它 我仍然会看到身份验证列,有人知道如何解决这个问题吗?

你好像忘了 link 资源 class 和你的 modeladmin

class ArtResource(resources.ModelResource):

    class Meta:
        model = Art
        exclude = ('authenticate', )

    class ArtAdmin(ImportExportModelAdmin):
        resource_class = ArtResource

    list_display = ['id', 'name', 'category', 'type', 'agent', 'authenticate', ]
    search_fields = ('name', 'category', 'artist', 'id', 'authenticate', )
    list_filter = ["authenticate"]
    actions = [approve_art, reject_art]