Django перетаскивание нескольких загрузок не работает

Я хочу сделать обновление текущего веб-приложения, которое я разработал с помощью Django. В текущей версии есть несколько полей для загрузки: enter image description here

И я изменил его на следующее: enter image description here

Теперь я не знаю, как обновить код, чтобы сделать то же самое, я сделал некоторые изменения, но я не могу получить файлы из дропзоны, используя request.FILES.getlist('files')

Вот мой старый код:

HTML:

<h5>Documents de base</h5>
{{ formset.management_form }}
{% for form in formset %}
    {{ form|crispy }}
{% endfor %}

Вид:

...................
if request.method == "POST":
    dossierForm = DossierForm(request.POST)
    formset = DocumentFormSet(
        request.POST, request.FILES, queryset=DocumentdeBase.objects.none()
    )
    formset2 = PhotoAvantFormSet(
        request.POST, request.FILES, queryset=PhotoAvant.objects.none()
    )
    if dossierForm.is_valid() and formset.is_valid() and formset2.is_valid():
...................
    for form in formset.cleaned_data:
                # this helps to not crash if the user
                # do not upload all the photos
                if form:
                    image = form["documentdebase_image"]
                    photo = DocumentdeBase(
                        dossier=dossier_form, documentdebase_image=image
                    )
                    photo.save()
            for form2 in formset2.cleaned_data:
                # this helps to not crash if the user
                # do not upload all the photos
                if form2:
                    image2 = form2["photoavant_image"]
                    photo2 = PhotoAvant(dossier=dossier_form, photoavant_image=image2)
                    photo2.save()
....................
else:
    dossierForm = DossierForm()
    formset = DocumentFormSet(queryset=DocumentdeBase.objects.none())
    formset2 = PhotoAvantFormSet(queryset=PhotoAvant.objects.none())

Форма:

class DocumentdebaseForm(forms.ModelForm):
    documentdebase_image = forms.ImageField(label="")

    class Meta:
        model = DocumentdeBase
        fields = ("documentdebase_image",)

Вот обновление, которое я сделал:

HTML: Documents de Base:

<div class="form-group mb-0">
                        <input id="input-b1" name="input-b1[]" type="file" class="file" data-browse-on-zone-click="true" multiple>
                    </div>

Photos avant:

<div class="form-group mb-0">
                        <input id="input-b2" name="input-b2[]" type="file" class="file" data-browse-on-zone-click="true" multiple>
                    </div>

Вот библиотеки и JS, которые я использовал:

Вид:

if request.method == "POST":
    dossierForm = DossierForm(request.POST)
    c = 1
    for f1 in request.FILES.getlist("input-b1"):
        print(f1)
        print(c)
        DocumentdeBase.objects.create(
            dossier__id=dossierForm.id, documentdebase_image=f1
        )
        PhotoAvant.objects.create(
            dossier__id=dossierForm.id, hotoavant_image=f2
        )
        c += 1
    x = 1
    for f2 in request.FILES.getlist("input-b2"):
        print(f2)
        print(x)
        DocumentdeBase.objects.create(
            dossier__id=dossierForm.id, documentdebase_image=f1
        )
        PhotoAvant.objects.create(
            dossier__id=dossierForm.id, hotoavant_image=f2
        )
        x += 1

Не обращайте внимания на переменные c и x, они нужны только для отладки.

Вот код, который я ввел, чтобы посмотреть, что я получу из HTML:

print("Documents de base:", request.FILES.getlist("input-b1"))

print("Photos avant:", request.FILES.getlist("input-b2"))

Вот какую ошибку я получаю в консоли:

Documents de base: []
Photos avant: []

Что я делаю не так? Я подозреваю HTML, но не уверен!

Вернуться на верх