/django-processorfield

A powerful filefield for Django with multiple processor outputs

Primary LanguagePythonBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Django-processorfield

A powerful filefield with multiple processor outputs.

Installation

Run pip install django-processorfield, or for the in-development version run pip install django-processorfield==dev.

Add processorfield to your INSTALLED_APPS setting:

INSTALLED_APPS = (
    ...
    'processorfield',
)

Fields

You can use FileProcessorField for easier access to retrieve or process files.

For example

from processorfield.fields import FileProcessorField
from PIL import Image
import StringIO

size = (100, 100)

def thumbnail(imagefile):
    output = StringIO.StringIO()
    im = Image.open(imagefile)
    im.thumbnail(size, Image.ANTIALIAS)
    im.save(outfile, "JPEG")
    return outfile

class Profile(models.Model):
    user = models.OneToOneField('auth.User')
    photo = FileProcessorField(upload_to='photos', processors={'thumbnail':thumbnail}, blank=True)

Accessing the field's predefined alias in a template

<img src="{{ profile.photo.thumbnail.url }}" alt="" />

Accessing the field's predefined alias in Python code

thumb_url = profile.photo['thumbnail'].url