I have written a code to upload an excel sheet and save the contents to mysql database. Below is the code to upload the file in memory.
form = UploadFileForm(request.POST,request.FILES)
if form.is_valid():
file_in_memory = request.FILES['file'].read()
wb = load_workbook(filename=BytesIO(file_in_memory), data_only=True)
Now, I want to upload a PDF file and save the path to mysql database using the same function. For instance, If excel has record A then there is an associated PDF file which I have to link. How do I handle this situation? Using formset is a solution? I am aware of multi-file upload but I assume that will save the file path to the database directly.
I believe you can do this directly in a
model.py
usingFileField
.