Welcome to django-upload-to documentation

PyPI - License Pypi Version Codecov Building Python Versions Django Versions

This site contains the project documentation for the django-upload-to project that is a django reusable app used in the Django projects.

Table of contents

  1. Tutorials
  2. How-To Guides
  3. Reference
  4. Explanation

Introduction

It generates dynamically a directory path and a secure file name for Django's FileField.

Main options:

  • Ready to use generators.
  • Generate secure file name without especial characters.
  • Generate file name using a uuid value.
  • Dynamically generate paths from the model instance.
  • Generate paths using Python datetime formats.

Get started

Install the django-upload-to in your virtual environment:

$ pip install django-upload-to

Import it in your models file and add it as a upload_to argument in the FileField

# my_app/models.py
from upload_to import UploadTo
from django.db import models


class MyModel(models.Model):
    attachment = models.FileField(upload_to=UploadTo("attachments"))

The path and file name generated will be like this:

"attachments/the-file-name-uploaded.pdf"
  1. Documentation
  2. Changelog
  3. PyPi Page
  4. Repository
  5. Bug Tracker