summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2024-04-04 23:18:36 +0100
committerGitHub <noreply@github.com>2024-04-04 19:18:36 -0300
commitba4ffdc8771c2f38cf6de26a2b82bbceea2b933a (patch)
treef6bd0f34fcc5d583924312b849c192058577be54 /docs
parente279c724c12b4edc808cd208245dfa6d10505879 (diff)
Refs #31710 -- Improved multiple file upload docs.
Diffstat (limited to 'docs')
-rw-r--r--docs/topics/http/file-uploads.txt16
1 files changed, 4 insertions, 12 deletions
diff --git a/docs/topics/http/file-uploads.txt b/docs/topics/http/file-uploads.txt
index 911c282157..b9a9bbf416 100644
--- a/docs/topics/http/file-uploads.txt
+++ b/docs/topics/http/file-uploads.txt
@@ -154,7 +154,7 @@ Uploading multiple files
should be updated after any changes in the following snippets.
If you want to upload multiple files using one form field, create a subclass
-of the field's widget and set the ``allow_multiple_selected`` attribute on it
+of the field's widget and set its ``allow_multiple_selected`` class attribute
to ``True``.
In order for such files to be all validated by your form (and have the value of
@@ -186,14 +186,14 @@ below for an example.
if isinstance(data, (list, tuple)):
result = [single_file_clean(d, initial) for d in data]
else:
- result = single_file_clean(data, initial)
+ result = [single_file_clean(data, initial)]
return result
class FileFieldForm(forms.Form):
file_field = MultipleFileField()
-Then override the ``post`` method of your
+Then override the ``form_valid()`` method of your
:class:`~django.views.generic.edit.FormView` subclass to handle multiple file
uploads:
@@ -209,19 +209,11 @@ uploads:
template_name = "upload.html" # Replace with your template.
success_url = "..." # Replace with your URL or reverse().
- def post(self, request, *args, **kwargs):
- form_class = self.get_form_class()
- form = self.get_form(form_class)
- if form.is_valid():
- return self.form_valid(form)
- else:
- return self.form_invalid(form)
-
def form_valid(self, form):
files = form.cleaned_data["file_field"]
for f in files:
... # Do something with each file.
- return super().form_valid()
+ return super().form_valid(form)
.. warning::