Skip to content

Commit 3cc64c4

Browse files
committed
Show already uploaded files on page reload. With delete button as well.
1 parent a427ea2 commit 3cc64c4

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

fileupload/templates/fileupload/picture_form.html

+23
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ <h1>Django Jquery file upload demo</h1>
4242
<table class="files"></table>
4343
<div class="fileupload-progressbar"></div>
4444
</div>
45+
46+
<div>
47+
{% if pictures %}
48+
<h2>Already uploaded</h2>
49+
<table class="table table-striped">
50+
{% for picture in pictures %}
51+
<tr>
52+
<td class="preview">
53+
<img src="{{ picture.file.url }}">
54+
</td>
55+
<td class="name">{{ picture.slug }}</td>
56+
<td class="delete">
57+
<a class="btn btn-danger" href="{% url 'upload-delete' picture.id %}">
58+
<i class="icon-trash icon-white"></i>
59+
<span>Delete</span>
60+
</button>
61+
</td>
62+
</tr>
63+
{% endfor %}
64+
</table>
65+
<p>(Removing from this list is left as an exercise to the reader)</p>
66+
{% endif %}
67+
</div>
4568
</div>
4669
<!-- modal-gallery is the modal dialog used for the image gallery -->
4770
<div id="modal-gallery" class="modal modal-gallery hide fade" data-filter=":odd">

fileupload/views.py

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def form_valid(self, form):
2424
response['Content-Disposition'] = 'inline; filename=files.json'
2525
return response
2626

27+
def get_context_data(self, **kwargs):
28+
context = super(PictureCreateView, self).get_context_data(**kwargs)
29+
context['pictures'] = Picture.objects.all()
30+
return context
31+
2732

2833
class PictureDeleteView(DeleteView):
2934
model = Picture

0 commit comments

Comments
 (0)