How can I replace / override the downloaded file?

I want to be able to upload a file and every download to override / replace an existing file with the latest version.

from django.core.files.storage import FileSystemStorage fs = FileSystemStorage(location='C:/temp', base_url='/attachments') class Import(models.Model): file = models.FileField(upload_to='data', storage=fs) 
+3
source share
1 answer

I don't know if this is the best approach, but the following lines helped me override / replace an existing file.

 upload_dir_path = Setting.objects.get(entry__exact='upload_path').value delete_files(upload_dir_path) upload = form.save(commit=False) upload.file.storage.location = upload_dir_path upload = form.save() 
+1
source

Source: https://habr.com/ru/post/1337311/


All Articles