Skip to main content

Small application that simplifies naming of uploaded files

Project description

Travis CI build status Code coverage percentage Latest version on PyPI Wheel Status Supported Python versions


Small application that simplifies naming of uploaded files. License is MIT.


You can get dj-upload-to release version from pypi with pip:

$ pip install dj-upload-to

or development one from github:

$ pip install -e git+

You’re not need include it into your INSTALLED_APPS


Assumes you have model:

from django.db import models
from dj_upload_to import UploadTo

upload_to = UploadTo()

class Model(models.Model):
    file = models.ImageField(upload_to=upload_to)

As you see, UploadTo generates callable object (with __call__ methodfor passing into upload_to attribute of FileField (see django upload_to docs for details)

When you save model with image originally named myphoto.JPG, file will be saved with name such as:



  • model is prefix automatically generated from model class. You can override it
  • ab is the first 2 char segment of filename
  • cd is the second 2 char segment of filename
  • abcdabcd-0123-4567-8901-234567890ab autogenerated with uuid filename
  • .jpg is a lower cased extension taken from original file


You can customize behavior of UploadTo with options in constructor:

  • prefix: prefix of filename. Default is None. If None, prefix will be generated by model class name
  • num_seg: number of parts of segmentation. Default is 2
  • seg_size: length of segment in chars. Default is 2
  • save_name: use original name without autogeneration. Default is False

There are some examples:

>>> model = Model()

>>> UploadTo(prefix='my_files')(model_instance, 'file.jpg')

>>> UploadTo(num_seg=4)(model_instance, 'file.jpg')

>>> UploadTo(seg_size=4)(model_instance, 'file.jpg')

>>> UploadTo(save_name=True)(model_instance, 'file.jpg')


Ideas, bugfixes, pull requests are welcome on GitHub

Project details

Download files

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

Files for dj-upload-to, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size dj_upload_to-1.0.0-py2-none-any.whl (5.4 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size dj-upload-to-1.0.0.tar.bz2 (3.9 kB) File type Source Python version None Upload date Hashes View
Filename, size dj-upload-to-1.0.0.tar.gz (3.5 kB) File type Source Python version None Upload date Hashes View
Filename, size (7.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page