Welcome to django-upload-to documentation
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
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"