Documentation |
Issues |
Changelog |
Funding 💚
Django Dynamic Filenames
Write advanced filename patterns using the Format String Syntax.
Sponsors
Getting Started
Installation
pip install django-dynamic-filenames
Samples
Basic example:
from django.db import models
from dynamic_filenames import FilePattern
upload_to_pattern = FilePattern(
filename_pattern="{app_label:.25}/{model_name:.30}/{instance.created:%Y-%m-%d}/{uuid:base32}{ext}"
)
class FileModel(models.Model):
my_file = models.FileField(upload_to=upload_to_pattern)
created = models.DateTimeField(auto_now_add=True)
Auto slug example:
Features
Field names
ext: File extension including the dot.name: Filename excluding the folders.model_name: Name of the Django model.app_label: App label of the Django model.instance: Instance of the model before it has been saved. You may not have a primary key at this point.uuid: UUID version 4 that supports multiple type specifiers. The UUID will be the same should you use it twice in the same string, but different on each invocation of theupload_tocallable.
The type specifiers allow you to format the UUID in different ways,
e.g. {uuid:x} will give you a with a hexadecimal UUID.
The supported type specifiers are:
s: String representation of a UUID including dashes.i: Integer representation of a UUID. Like toUUID.int.x: Hexadecimal (Base16) representation of a UUID. Like toUUID.hex.X: Upper case hexadecimal representation of a UUID. Like toUUID.hex.base32: Base32 representation of a UUID without padding.base64: Base64 representation of a UUID without padding.
All type specifiers also support precisions to cut the string,
e.g. {{uuid:.2base32}} would only return the first 2 characters of a Base32 encoded UUID.
Type specifiers
You can also use a special slug type specifier, that slugifies strings.
Example:
from django.db import models
from dynamic_filenames import FilePattern
upload_to_pattern = FilePattern(
filename_pattern="{app_label:.25}/{model_name:.30}/{instance.title:.40slug}{ext}"
)
class FileModel(models.Model):
title = models.CharField(max_length=100)
my_file = models.FileField(upload_to=upload_to_pattern)
Slug type specifiers also support precisions to cut the string. In the example above the slug of the instance title will be cut at 40 characters.
Metadata
Release files for django-dynamic-filenames 1.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_dynamic_filenames-1.5.0.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_dynamic_filenames-1.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.7 kB
Release files / django_dynamic_filenames-1.5.0.tar.gz
| Download URL | django_dynamic_filenames-1.5.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e0af1bc496d356636896b85c56154ffabcef62122b1417948b3590ebd8afe2bb
|
|
BLAKE2b-256 checksum How to use checksums |
dc0b50127a1604f69b92b64d1c2cfa617b6e6a49e9f4b05ba4c72c088c32aa02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / django_dynamic_filenames-1.5.0-py3-none-any.whl
| Download URL | django_dynamic_filenames-1.5.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
06b2494a5ac6f6db8b085af7dc555ce44ad4e41f7796c732a05f42fb18231d3b
|
|
BLAKE2b-256 checksum How to use checksums |
3b28c33b3638159bd4be6d537ef24d35959338a8d50952bd402f0129cb9286a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency log