1👍
✅
I couldn’t see how you delete a Document
. You should have a method like the following.
def delete(request):
if request.method != 'POST':
raise HTTP404 # don't forget to import
else:
docId = request.POST.get('doc-id', None)
if docId is not None:
docToDel = Document.objects.get(pk=docId)
# delete the file using docToDel.docfile
docToDel.delete()
return HttpResponse('Whatever message you want.')
UPDATE 1
If you would like to delete objects automatically when a file deleted directly, you could iterate the Document objects and check if the files are existing or not. But you need to run this procedure before listing or periodically.
Source:stackexchange.com