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-multiplefilefield
with a package manage tool which you prefered the most, for example, to me it's pip:
pip install django-multiplefilefield
- Add
multiplefilefield
to yourINSTALLED_APPS
tuple in your settings file settings*.py:
INSTALLED_APPS = (
# …
"multiplefilefield",
)
- Fortunately,
multiplefilefield
provides the compatibility to the common single file FileField in Django. You can easily changemodels.FileField
toMultipleFileModelField
, 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_example
app:
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 !