Django-import-export: can I use django-import-export import fields different with the export fields?

Created on 28 Oct 2016  路  5Comments  路  Source: django-import-export/django-import-export

I found with django-import-export, the import fields and export fields is the same, but I want to set different fields when importing and exporting, I don't know whether django-import-export support that?

stale

Most helpful comment

This would use BookResource for import and ExportBookResouce for export.

class BookAdmin(ImportExportModelAdmin):
    resource_class = BookResource

    def get_export_resource_class(self):
        """
        Returns ResourceClass to use for export.
        """
        return ExportBookResource

All 5 comments

Off course, use 2 resources.

hi @bmihelac , can I ask a simple example 馃槉 , I am not actually understand the documentation. 馃槩

This would use BookResource for import and ExportBookResouce for export.

class BookAdmin(ImportExportModelAdmin):
    resource_class = BookResource

    def get_export_resource_class(self):
        """
        Returns ResourceClass to use for export.
        """
        return ExportBookResource

Have you tried overriding Resource.get_export_fields()? https://github.com/django-import-export/django-import-export/blob/master/import_export/resources.py#L597

We use that to change both what fields are visible on the import screen, as well as what fields get exported.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings