1
votes

I've been scouring the docs and internet for a couple days now trying to figure out how I can capture the imported filename from Django import export admin panel's import feature.

Basically, I want to save this filename to ensure that future file uploads are not the same.

the process being:

  1. Someone imports a file

picture of admin panel with import button

  1. The filename is stored

admin panel, import file section

  1. If someone tries to upload same file again, error

error in file import

But I can't figure out how to get that filename from Django import export. Help is much appreciated.

Update 2/15/2018: I'm creating a work-around in the views.py using tablib and intercepting the data before Django-import-export takes over. Spirits are high.

1

1 Answers

1
votes

You could get the file name in many pre/post function parameters, my example updating the file name of the records:

class MyResouce(resources.ModelResource):
    class Meta:
        model = MyDjangoModel

    def after_import_instance(self, instance, new, **kwargs):
        # update file name
        file_name = kwargs.get('file_name', 'unknown')
        instance.source = file_name