[Solved]-Django-import-export – import of advanced fields?

5👍

You can override import_obj instead. See Import workflow for more details.

Another approach is to subclass Field and override export and save methods and do all required data manipulation in a field.

1👍

I know this is very old but I came across the same problem and this is how I fixed it (based on the direction the original asker was heading).
First, you can add any custom/modified fields you need by overriding the ‘before_import_row’ function, like so:

    def before_import_row(self, row, **kwargs):
        row['extra_info'] = 'Some Info'
        return super(RetailLocationResource, self).before_import_row(row, **kwargs)

Then you can pass this into your instance by overriding get_or_init_instance like so:

    def get_or_init_instance(self, instance_loader, row):
        instance, bool = super(RetailLocationResource, self).get_or_init_instance(instance_loader, row)
        instance.extra_info = row['extra_info']
        return instance, bool

Hope this helps anyone!

Leave a comment