0

I'm building a web app in Django. There I have a model DocFile with a FileField upload.

class DocFile(models.Model):
    name = models.CharField('Bezeichnung', max_length=100)
    md5sum = models.CharField(max_length=32)
    upload = models.FileField('Datei', upload_to=media_file_name, storage=MediaFileSystemStorage())

In the following view, I try to delete the database entry (not the file in my media dir) of DocFile where pk=pd.

def delete_doc(request, pd, pk):
    doc = get_object_or_404(DocFile, pk=pd)
    doc.delete()
    return redirect('list_docfile', pk=pk)

But sadly the delete() command deletes both the database entry and the file in the media dir. I tried to search for a solution but all I got was this: Django delete FileField

If Django removed the function that delete() removes the file of the FileField, why does the command still removes both in my Django application.

cezar
  • 11,616
  • 6
  • 48
  • 84

0 Answers0