Getting values from django database
I'm just learning python and django. I am writing a thing that reads the values in the xlsx file, and if the values are similar to those in the database, then the value in the adjacent column in the xlsx file changes to the one I specify
models.py
class imgUpload(models.Model):
title = models.CharField(max_length=100)
img = models.ImageField(upload_to='img')
def __str__(self):
return self.title
views.py
def upload_xlsx(request):
if request.method == 'POST':
form = xlsxForm(request.POST, request.FILES)
if form.is_valid():
form.save()
fileName = xlsxUpload.objects.last()
fileNameStr = str(fileName.file)
book = load_workbook(fileNameStr)
sheet: worksheet = book.worksheets[0]
for row in range(2, sheet.max_row + 1):
a = sheet[row][0].value
fileNameImg = imgUpload.objects.all()
fileNameImgStr = fileNameImg.filter(title=a)
if a == fileNameImgStr:
sheet[row][1].value = str(fileNameImgStr)
book.save(fileNameStr)
book.close()
return redirect('xlsx_list')
else:
form = xlsxForm()
return render(request, 'img/upload_xlsx.html', {
'form': form
})
I have achieved that it takes all the values, but does not compare them