我很难将所选文件的django Dropzonejs值放入django。它只是在模型中创建一个空文件对象。问题是我无法将值输入模型。它只是创建一个空白模型。
HTML:
<form class="dropzone" action="{% url 'teacher_assignment_add_file' OBJECTID %}" method="POST">
{% csrf_token %}
<div class="fallback">
<input name="Assignment-File" type="file" multiple />
</div>
</form>
<ul class="list-group list-group-activity dropzone-previews flex-column-reverse">
{% for file in files %}
<li class="list-group-item">
<div class="media align-items-center">
<ul class="avatars">
<li>
<div class="avatar bg-primary">
<i class="material-icons">insert_drive_file</i>
</div>
</li>
</ul>
<div class="media-body d-flex justify-content-between align-items-center">
<div>
<a href="{% url 'file123' file %}" data-filter-by="text">{{ file }}</a>
<br>
</div>
<div class="dropdown">
<button class="btn-options" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="material-icons">more_vert</i>
</button>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#">Download</a>
<a class="dropdown-item" href="#">Share</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger" href="#">Delete</a>
</div>
</div>
</div>
</div>
</li>
{% endfor %}
查看:
@login_required
def teacher_assignment_add_files(request, assignment_id):
if request.method == 'POST':
file = request.POST.get('Assignment-File')
file = File(file=file)
file.save()
assignment = Assignment(id=assignment_id)
assignment.files.add(file.id)
return redirect('teacher-detail-assignment', id = assignment_id)