I\'ve tried to import a csv file into a database by tweaking the modelform inside the admin doing this:
models.py:
class Data(models.Model):
plac
In the save()
method, you don't have any access to the request object - you can see that it's not passed in. Normally you would expect to have a NameError
there, but I suspect that you've got a function elsewhere in the file called request()
.
At the point of saving, all the relevant data should be in cleaned_data
: so you should be able to do
file_csv = self.cleaned_data['file_to_import']
At that point you'll have another problem, which is when you get to open
- you can't do that, as file_to_import
is not a file on the server filesystem, it's an in-memory file that has been streamed from the client. You should be able to pass file_csv
directly to csv.reader
.