Before explaining my problem in detail, here are my codes.
models.py
class SimilarStore(models.Model):
store = models.ForeignKey(Store)
domain = models.CharField(max_length=100, blank=True)
score = models.IntegerField(blank=True)
rank = models.IntegerField(blank=True)
created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateTimeField(auto_now=True)
forms.py
class SimilarStoreForm(forms.ModelForm):
similarstore_csv = forms.FileField()
class Meta:
model = SimilarStore
fields = ('store', 'similarstore_csv')
def save(self, commit=False, *args, **kwargs):
form_input = SimilarStoreForm()
self.store = self.cleaned_data['store']
csv_file = self.cleaned_data['similarstore_csv']
for line in csv_file:
self.domain = line[0]
self.score = line[1]
self.rank = line[2]
form_input.save()
data.csv
roolee.com,100,125225
piperandscoot.com,29.3,222166
calledtosurf.com,23.8,361542
cladandcloth.com,17.9,208670
neeseesdresses.com,9.6,251016
...
I'm trying to upload data.csv
to DB. I need each column data in the file to go into domain
, score
, rank
in SimilarStore
model. This is what I'm trying to do with the above codes.
However, when I upload the file and submit it, an error shows up, saying
expected str, bytes or os.PathLike object, not InMemoryUploadedFile
I've done some research about it, but nothing worked for my case. Can anyone figure out anything wrong?