Opened 11 months ago

Last modified 9 days ago

#28554 assigned New feature

Add support for multiple file fields

Reported by: Johannes Hoppe Owned by: Johannes Hoppe
Component: File uploads/storage Version: master
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


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.

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 (10)

comment:1 Changed 11 months ago by Johannes Hoppe

Owner: changed from nobody to Johannes Hoppe
Status: newassigned

comment:2 Changed 11 months ago by Johannes Hoppe

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 the TextField.

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]( and [django-stdimage]( and have some experience with custom the FileInput and FileField. Let me know if I can be of any help.


comment:3 Changed 11 months ago by Claude Paroz

Triage Stage: UnreviewedAccepted
Version: 1.11master

+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 Changed 11 months ago by Johannes Hoppe

Has patch: set
Needs documentation: set
Needs tests: set
Patch needs improvement: set

comment:5 Changed 10 months ago by Johannes Hoppe

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:6 Changed 9 months ago by Thomas Güttler

Just for the records, this lib tries to solve this:

Django Multiupload

Dead simple drop-in multi file upload field for django forms using HTML5's multiple attribute.

Last edited 9 months ago by Thomas Güttler (previous) (diff)

comment:7 Changed 7 months ago by Johannes Hoppe

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 Changed 4 months ago by Tim Graham

Patch needs improvement: set

comment:9 Changed 4 months ago by Johannes Hoppe

Patch needs improvement: unset

comment:10 Changed 9 days ago by Tim Graham

Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top