Project for merging different file types, as example easy thumbnail image and unpacking archive in one field
pip install django-multitype-file-field
or from git
pip install -e git+https://github.com/Apkawa/django-multitype-file-field.git#egg=django-multitype-file-field| Python Django |
3.5 | 3.6 | 3.7 | 3.8 |
|---|---|---|---|---|
| 1.8 | ❌ | ❌ | ❌ | ❌ |
| 1.11 | ✔️ | ✔️ | ✔️ | ❌ |
| 2.2 | ✔️ | ✔️ | ✔️ | ✔️ |
| 3.0 | ❌ | ✔️ | ✔️ | ✔️ |
from django.db import models
from multitype_file_field.fields import MultiTypeFileField
# as example, with easy_thumbnails
from easy_thumbnails.fields import ThumbnailerImageField
class FileModel(models.Model):
file = MultiTypeFileField(upload_to='test_archive',
fields={
None: models.FileField, # Fallback
'image/svg+xml': models.FileField, # high priority,
'image': (
ThumbnailerImageField,
dict(resize_source=dict(size=(100, 100), sharpen=True, crop='smart'))
), # tuple, Field and args
}
)Usage:
from tests.models import TestModel
from django.core.files.base import ContentFile
model = TestModel()
model.file # => <FieldFile: None>
model.file = ContentFile('', name='example.png')
model.file # => <ImageFieldFile: example.png>
model.file = ContentFile('', name='example.txt')
model.file # => <FieldFile: example.txt>pip install -r requirements-dev.txt
./test/manage.py migrate
./test/manage.py runserverpip install -r requirements-dev.txt
pytest
toxpython setup.py bumpversionpython setup.py publish