A multiple file field implementation in Django.
It works well with Django-1.8.18 Python 2.7. Welcome to test it in other version and PR.
- You can install
django-multiplefilefieldwith a package manage tool which you prefered the most, for example, to me it's pip:
pip install django-multiplefilefield- Add
multiplefilefieldto yourINSTALLED_APPStuple in your settings file settings*.py:
INSTALLED_APPS = (
# …
"multiplefilefield",
)- Fortunately,
multiplefilefieldprovides the compatibility to the common single file FileField in Django. You can easily changemodels.FileFieldtoMultipleFileModelField, do something to update your old field like:
./manage.py makemigrations
./manage.py migrate- Or create a new model to have a try with it, just like what I did in the
multiplefilefield_exampleapp:
from django.db import models
from multiplefilefield.fields import MultipleFileModelField
class SimpleMultipleFileFieldModel(models.Model):
hash = models.CharField(name="hash", max_length=128)
files = MultipleFileModelField(name="files")- Once you created a model with
MultipleFileModelField, you can use it just like the traditional model withFileField.
In the template, please do like this (object can be a SimpleMultileFileFieldModel instance)
{% if object.files %}
{% for file in object.files %}
<li><a href="{{ file.url }}">{{file.name}}</a></li>
{% endfor %}
{% endif %}In the form, all will be okay. It will be rendered as a <input/> with attribute multiple .
So just Command + Click to choose multiple files in Mac, Ctrl + Click in PC. In the smartphones, surely you can choose many files !