Skip to content

Commit ce1b0d0

Browse files
committed
Switch README to Markdown
1 parent ced1c19 commit ce1b0d0

File tree

3 files changed

+111
-120
lines changed

3 files changed

+111
-120
lines changed

README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Django Dynamic Filenames
2+
3+
Write advanced filename patterns using the [Format String
4+
Syntax](https://docs.python.org/3/library/string.html#format-string-syntax).
5+
6+
## Getting Started
7+
8+
### Installation
9+
10+
``` sourceCode bash
11+
pip install django-dynamic-filenames
12+
```
13+
14+
### Samples
15+
16+
Basic example:
17+
18+
``` sourceCode python
19+
from django.db import models
20+
from dynamic_names import FilePattern
21+
22+
upload_to_pattern = FilePattern(
23+
filename_pattern='{app_name:.25}/{model_name:.30}/{uuid:base32}{ext}'
24+
)
25+
26+
class FileModel(models.Model):
27+
my_file = models.FileField(upload_to=upload_to_pattern)
28+
```
29+
30+
Auto slug example:
31+
32+
## Features
33+
34+
### Field names
35+
36+
- `ext`
37+
File extension including the dot.
38+
39+
- `name`
40+
Filename excluding the folders.
41+
42+
- `model_name`
43+
Name of the Django model.
44+
45+
- `app_label`
46+
App label of the Django model.
47+
48+
- `instance`
49+
Instance of the model before it has been saved. You may not have a
50+
primary key at this point.
51+
52+
- `uuid`
53+
UUID version 4 that supports multiple type specifiers. The UUID will
54+
be the same should you use it twice in the same string, but
55+
different on each invocation of the `upload_to` callable.
56+
57+
The type specifiers allow you to format the UUID in different ways,
58+
e.g. `{uuid:x}` will give you a with a hexadecimal UUID.
59+
60+
The supported type specifiers are:
61+
62+
- `s`
63+
String representation of a UUID including dashes.
64+
65+
- `i`
66+
Integer representation of a UUID. Like to `UUID.int`.
67+
68+
- `x`
69+
Hexadecimal (Base16) representation of a UUID. Like to
70+
`UUID.hex`.
71+
72+
- `X`
73+
Upper case hexadecimal representation of a UUID. Like to
74+
`UUID.hex`.
75+
76+
- `base32`
77+
Base32 representation of a UUID without padding.
78+
79+
- `base64`
80+
Base64 representation of a UUID without padding.
81+
82+
**Warning:** Not all file systems support Base64 file names.
83+
84+
All type specifiers also support precisions to cut the string, e.g.
85+
`{{uuid:.2base32}}` will return the first 2 characters of a Base32
86+
encoded UUID.
87+
88+
### Type specifiers
89+
90+
You can also use a special slug type specifier, that slugifies strings.
91+
92+
Example:
93+
94+
``` sourceCode python
95+
from django.db import models
96+
from dynamic_names import FilePattern
97+
98+
upload_to_pattern = FilePattern(
99+
filename_pattern='{app_name:.25}/{model_name:.30}/{instance.title:.40slug}{ext}'
100+
)
101+
102+
class FileModel(models.Model):
103+
title = models.CharField(max_length=100)
104+
my_file = models.FileField(upload_to=upload_to_pattern)
105+
```
106+
107+
Slug type specifiers also support precisions to cut the string. In the
108+
example above the slug of the instance title will be cut at 40
109+
characters.

README.rst

Lines changed: 0 additions & 118 deletions
This file was deleted.

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name = django-dynamic-filenames
33
author = Johannes Hoppe
44
author-email = info@johanneshoppe.com
55
summary = Write advanced filename patterns using the Format String Syntax.
6-
description-file = README.rst
7-
description-content-type = text/x-rst; charset=UTF-8
6+
description-file = README.md
7+
description-content-type = text/markdown; charset=UTF-8
88
home-page = https://github.com/codingjoe/django-dynamic-filenames
99
license = MIT
1010
classifier =

0 commit comments

Comments
 (0)