I've been working with Django import-export so that I can get csv files from my database. These csv files have some fields that aren't relevant since they are changed when items are put into the database and thus I dont want them in the table.
I have followed the docs for import-export but can't seem to exclude these fields properly. in my admin.py file I have:
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', )
When I go into python manage.py shell and get it to print out the csv it is how I expect it to be, however when I use python manage.py runserver and then export it I will still see the authenticate column, does anyone know how to fix this?
It seems you forgot to link the resource class with you 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]