Skip to content
Snippets Groups Projects
Commit ad8ca7f1 authored by baoshun yan's avatar baoshun yan
Browse files

can delete

parent 03ebd20e
No related branches found
No related tags found
No related merge requests found
......@@ -5,12 +5,22 @@
<h2>Project template</h2>
<div>
<a href="{% url 'upload' %}">Upload file</a>
<a href="{% url 'upload' %}">Upload file</a><hr>
<div>
{% for file in audio_files %}
<div>
<h5> {{ file.name }} -- added by {{ file.owner }} -- {{ file.created }}</h5>
</div>
<div>
{{ file.name }} -- added by {{ file.owner }} -- {{ file.created }}
{# {% url delete audio_file_id=file.id as delete_url %}#}
<form method="POST"
style="display: inline;"
action="/deleteFile/{{ file.id }}/">
{% csrf_token %}
<input type="submit" value="Delete"/>
</form>
<hr>
</div>
{% endfor %}
</div>
......
......@@ -6,7 +6,7 @@
<form method="POST" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" />
<input type="submit" value="Upload"/>
</form>
</div>
......
......@@ -3,5 +3,6 @@ from . import views
urlpatterns = [
path('', views.home, name="home"),
path('upload-file/', views.upload_file, name="upload")
path('uploadFile/', views.upload_file, name="upload"),
path('deleteFile/<int:audio_file_id>/', views.delete_file, name="delete"),
]
......@@ -19,4 +19,10 @@ def upload_file(request):
return redirect('home')
context = {'form': form}
return render(request, 'base/upload_form.html', context)
return render(request, 'base/upload_file.html', context)
def delete_file(request, audio_file_id):
audio_file_to_delete = AudioFile.objects.get(id=audio_file_id)
audio_file_to_delete.delete()
return redirect('home')
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment