def delete_report(request, rid): report = get_object_or_404(Report, id=rid) form = DeleteReportForm(instance=report) if request.method == 'POST': form = DeleteReportForm(request.POST, instance=report) if form.is_valid(): report.file.delete() report.delete() messages.add_message(request, messages.SUCCESS, 'Report deleted successfully.', extra_tags='alert-success') return HttpResponseRedirect(reverse('reports')) else: messages.add_message(request, messages.ERROR, 'Unable to delete Report, please try again.', extra_tags='alert-danger') else: return HttpResponseForbidden()