Skip to main content

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

Project description

# Django Multiupload

[![Build Status](https://travis-ci.org/Chive/django-multiupload.svg?branch=master)](https://travis-ci.org/Chive/django-multiupload)


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

## Installation

* Install the package using pip (or easy_install if you really have to)

```bash
$ pip install django-multiupload
```

* Or directly from this repository to get the development version (if you're feeling adventurous)

```bash
$ pip install -e git+https://github.com/Chive/django-multiupload.git#egg=multiupload
```

## Usage

Add the form field to your form and make sure to save the uploaded files in the form's ``save`` method.

For more detailed examples visit the [examples section](https://github.com/Chive/django-multiupload/tree/master/examples).


```python
# forms.py
from django import forms
from multiupload.fields import MultiFileField

class UploadForm(forms.Form):
attachments = MultiFileField(min_num=1, max_num=3, max_file_size=1024*1024*5)

# If you need to upload media files, you can use this:
attachments = MultiMediaField(
min_num=1,
max_num=3,
max_file_size=1024*1024*5,
media_type='video' # 'audio', 'video' or 'image'
)

# For images (requires Pillow for validation):
attachments = MultiImageField(min_num=1, max_num=3, max_file_size=1024*1024*5)
```

The latter two options just add fancy attributes to HTML's `<input>`, restricting the scope to corresponding filetypes.

```python
# models.py
from django.db import models

class Attachment(models.Model):
file = models.FileField(upload_to='attachments')

```

```python
# views.py
from django.views.generic.edit import FormView
from .forms import UploadForm
from .models import Attachment

class UploadView(FormView):
template_name = 'form.html'
form_class = UploadForm
success_url = '/done/'

def form_valid(self, form):
for each in form.cleaned_data['attachments']:
Attachment.objects.create(file=each)
return super(UploadView, self).form_valid(form)

```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-multiupload-0.5.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

django_multiupload-0.5.2-py2-none-any.whl (7.4 kB view details)

Uploaded Python 2

File details

Details for the file django-multiupload-0.5.2.tar.gz.

File metadata

File hashes

Hashes for django-multiupload-0.5.2.tar.gz
Algorithm Hash digest
SHA256 43789280095fc5491dff3a6da22280571bb79333427e6ba007298165e128ad93
MD5 b3518582b374c17c9a8f972850cf7dfb
BLAKE2b-256 d3322b794848312bba7fe1bd48401a7b464b89a6e2417ea6184d6b8075ece311

See more details on using hashes here.

File details

Details for the file django_multiupload-0.5.2-py2-none-any.whl.

File metadata

File hashes

Hashes for django_multiupload-0.5.2-py2-none-any.whl
Algorithm Hash digest
SHA256 0a4193efbe2bfb1e8cd14b2df11de6a36923ddf2458ce97a70306a25b8bf4e60
MD5 c6df055cb0e70a773a270a765134f07d
BLAKE2b-256 98e49489990360ef3e486da400d061547a6af3c29df94caf60d58a78fe594a8b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page