App for Django featuring improved form base classes.
Project description
[](https://travis-ci.org/Apkawa/django-multitype-file-field)
[](https://requires.io/github/Apkawa/django-multitype-file-field/requirements/?branch=master)
[]()
Project for merging different file types, as example easy thumbnail image and unpacking archive in one field
# Installation
```bash
pip install django-multitype-file-field
```
or from git
```bash
pip install -e git+https://github.com/Apkawa/django-multitype-file-field.git#egg=django-multitype-file-field
```
# Usage
## models.py
```python
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
}
)
```
```python
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>
```
# Contributing
## run tests
```bash
pip install -r requirements.txt
./test/manage.py migrate
pytest
tox
```
## publish pypi
```bash
python setup.py sdist upload -r pypi
```
[](https://requires.io/github/Apkawa/django-multitype-file-field/requirements/?branch=master)
[]()
Project for merging different file types, as example easy thumbnail image and unpacking archive in one field
# Installation
```bash
pip install django-multitype-file-field
```
or from git
```bash
pip install -e git+https://github.com/Apkawa/django-multitype-file-field.git#egg=django-multitype-file-field
```
# Usage
## models.py
```python
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
}
)
```
```python
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>
```
# Contributing
## run tests
```bash
pip install -r requirements.txt
./test/manage.py migrate
pytest
tox
```
## publish pypi
```bash
python setup.py sdist upload -r pypi
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-multitype-file-field-0.0.4.tar.gz.
File metadata
- Download URL: django-multitype-file-field-0.0.4.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a089d8dd4eb769d7d5f27e5202a71eb11456bbfbf36a630339f2cfc8478562ce
|
|
| MD5 |
0faa61b154fdcc6e3e6bea75e79a723a
|
|
| BLAKE2b-256 |
bdc7540fa75adc531121dca8fd5213fd452c772a8d45c34ae3e75dbe9d422b02
|