Opened 7 years ago
Last modified 6 years ago
#28554 assigned New feature
Add support for multiple file fields
Reported by: | Johannes Maron | Owned by: | Johannes Maron |
---|---|---|---|
Component: | File uploads/storage | Version: | dev |
Severity: | Normal | Keywords: | file, storage, upload, multiple, input |
Cc: | info@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
The django.db.models.FileField
currently allows only to store a single file URL.
This behavior seems outdated considering that input[type=file]
supports a multiple
attribute, which is supported by all major Browsers.
See: https://www.w3schools.com/tags/att_input_multiple.asp
I would suggest to have a similar attribute on the database field itself, as well as on the form field and widget.
The major point for discussion would be how to store the data. The easiest would be to coma separate the paths in a single char field. The major concern here would be the lack of atomicity. For databases like Postgres I would be sensical to use the ArrayField
as an underlying structure. Another way for serialisation would be the use of JSONs in a char field.
All solutions based on a text or char field have an issue related to the compatibility with the current FileField
which is limited to 100 characters. The type would need to be migrated to a text type or the length would need to be increased. The latter options bares the question to which point.
Another approach would be to defer the storage issue and only provide support for multiple files on form level.
This would mean to add a multiple
attribute to the form field and widget. Users would be able to create forms with multiple files in a single field and handle storage according to their preference.
Change History (12)
comment:1 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 7 years ago
comment:3 by , 7 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.11 → master |
+1 to adding multiple
at the form layer.
About storage, I'm not sure we'll find a common enough use case to implement a storage strategy in Django itself. I guess that second part warrants a discussion on django-developers.
comment:4 by , 7 years ago
Has patch: | set |
---|---|
Needs documentation: | set |
Needs tests: | set |
Patch needs improvement: | set |
comment:5 by , 7 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Patch needs improvement: | unset |
comment:6 by , 7 years ago
Just for the records, this lib tries to solve this: https://github.com/Chive/django-multiupload
Django Multiupload Dead simple drop-in multi file upload field for django forms using HTML5's multiple attribute.
comment:7 by , 7 years ago
Thanks Thomas, I took a look at the package. It does a lot more than what I want to implement here. Still it would make sense to add basic support to Django.
comment:8 by , 7 years ago
Patch needs improvement: | set |
---|
comment:9 by , 7 years ago
Patch needs improvement: | unset |
---|
comment:10 by , 6 years ago
Patch needs improvement: | set |
---|
comment:11 by , 6 years ago
Patch needs improvement: | unset |
---|
comment:12 by , 6 years ago
Patch needs improvement: | set |
---|
I tried to exclude my personal opinion and preference from the ticket description, to have an open discussion.
So here goes my personal opinion:
It seems odd to me that the
FileField
is limited to 100 characters. I could not find any reference to why the field was limited in the first place. Furthermore I do not know of any file system with a 100 char limitation nor are URLs limited to only 100 chars.Therefore I would suggest basing the
FileField
upon theTextField
.I would recommend splitting the issue tho. I would first add support form multiple files to form. This is a nice feature in itself and requires little work and good documentation. I would presume that such a feature would spawn a larger discussion on how to store those files. As multiple model instances? As an Array in Postgres? As CSV or JSON in a
TextField
? I think we can figure this out later or not at all if we don't come to a conclusion.I would love to work on that. I do maintain [django-s3file](https://github.com/codingjoe/django-s3file/) and [django-stdimage](https://github.com/codingjoe/django-stdimage/) and have some experience with custom the
FileInput
andFileField
. Let me know if I can be of any help.Cheers
-joe