[Answer]-Uploading/Deleting files from a database in Django

1👍

You don’t wanna handle too much in one view. You could, but it makes ugly hard to maintain code. Better add a separate view for deleting. With this in your template loop.

<a href='{% url 'delete_document' pk=document.pk %}'>delete</a> 

Then add a new url pattern with a pk argument:

url(r'^document/delete/(?P<pk>\d+)/$', "delete_document", name="delete_document"),

And a view like:

def delete_document(request, pk):
    try:
        Docuent.objects.get(pk=pk).delete()
    except Document.DoesNotExist:
        pass
    return HttpResponseRedirect(...)

Leave a comment