I am creating a website in which the user uploaded a zip
file.
This zip file is the unzipped, saved inside my project folder.
Then I want to retrieve these files and saved it into my Model.
I managed to unzip the file in a folder inside my DJango project but now I do not know how to pass them into my views so that they can be saved in the Models.
views.py
def homeupload(request):
if request.method == "POST":
my_entity = Uploading()
my_zip_file = request.FILES["my_uploads"]
with zipfile.ZipFile(my_zip_file, 'r') as zip_ref:
zip_ref.extractall('media/documents/')
my_entity.my_uploads = "RETRIEVE THE UNZIPPED FILE FOLDER FROM media/documents/"
my_entity.save()
messages.success(request, "File uploaded correctly")
return redirect('homeupload')
return render(request, 'uploadings/homeupload.html')
models.py
class Uploading(models.Model):
my_uploads = models.FileField(upload_to="documents/")