|
| 1 | +<p align="center"> |
| 2 | + <picture> |
| 3 | + <source media="(prefers-color-scheme: dark)" srcset="https://github.com/codingjoe/django-dynamic-filenames/raw/main/images/logo-dark.svg"> |
| 4 | + <source media="(prefers-color-scheme: light)" srcset="https://github.com/codingjoe/django-dynamic-filenames/raw/main/images/logo-light.svg"> |
| 5 | + <img alt="Django DynFN: Advanced filename patterns using f-Strings" src="https://github.com/codingjoe/django-dynamic-filenames/raw/main/images/logo-light.svg"> |
| 6 | + </picture> |
| 7 | +<br> |
| 8 | + <a href="https://github.com/codingjoe/django-dynamic-filenames?tab=readme-ov-file">Documentation</a> | |
| 9 | + <a href="https://github.com/codingjoe/django-dynamic-filenames/issues/new/choose">Issues</a> | |
| 10 | + <a href="https://github.com/codingjoe/django-dynamic-filenames/releases">Changelog</a> | |
| 11 | + <a href="https://github.com/sponsors/codingjoe">Funding</a> 💚 |
| 12 | +</p> |
| 13 | + |
1 | 14 | # Django Dynamic Filenames |
2 | 15 |
|
3 | | -Write advanced filename patterns using the [Format String |
4 | | -Syntax](https://docs.python.org/3/library/string.html#format-string-syntax). |
| 16 | +Write advanced filename patterns using the [Format String Syntax](https://docs.python.org/3/library/string.html#format-string-syntax). |
5 | 17 |
|
6 | 18 | ## Getting Started |
7 | 19 |
|
@@ -35,77 +47,32 @@ Auto slug example: |
35 | 47 |
|
36 | 48 | ### Field names |
37 | 49 |
|
38 | | -`ext` |
39 | | - |
40 | | -: File extension including the dot. |
41 | | - |
42 | | -`name` |
43 | | - |
44 | | -: Filename excluding the folders. |
45 | | - |
46 | | -`model_name` |
47 | | - |
48 | | -: Name of the Django model. |
49 | | - |
50 | | -`app_label` |
| 50 | +- `ext`: File extension including the dot. |
| 51 | +- `name`: Filename excluding the folders. |
| 52 | +- `model_name`: Name of the Django model. |
| 53 | +- `app_label`: App label of the Django model. |
| 54 | +- `instance`: Instance of the model before it has been saved. You may not have a primary key at this point. |
| 55 | +- `uuid`: UUID version 4 that supports multiple type specifiers. |
| 56 | + The UUID will be the same should you use it twice in the same string, |
| 57 | + but different on each invocation of the `upload_to` callable. |
51 | 58 |
|
52 | | -: App label of the Django model. |
53 | | - |
54 | | -`instance` |
55 | | - |
56 | | -: Instance of the model before it has been saved. You may not have a |
57 | | -primary key at this point. |
58 | | - |
59 | | -`uuid` |
60 | | - |
61 | | -: UUID version 4 that supports multiple type specifiers. The UUID will |
62 | | -be the same should you use it twice in the same string, but |
63 | | -different on each invocation of the `upload_to` callable. |
64 | | - |
65 | | -``` |
66 | 59 | The type specifiers allow you to format the UUID in different ways, |
67 | 60 | e.g. `{uuid:x}` will give you a with a hexadecimal UUID. |
68 | 61 |
|
69 | 62 | The supported type specifiers are: |
70 | 63 |
|
71 | | -`s` |
| 64 | +- `s`: String representation of a UUID including dashes. |
| 65 | +- `i`: Integer representation of a UUID. Like to `UUID.int`. |
| 66 | +- `x`: Hexadecimal (Base16) representation of a UUID. Like to `UUID.hex`. |
| 67 | +- `X`: Upper case hexadecimal representation of a UUID. Like to `UUID.hex`. |
| 68 | +- `base32`: Base32 representation of a UUID without padding. |
| 69 | +- `base64`: Base64 representation of a UUID without padding. |
72 | 70 |
|
73 | | -: String representation of a UUID including dashes. |
| 71 | +> [!WARNING] |
| 72 | +> Not all file systems support Base64 file names. |
74 | 73 |
|
75 | | -`i` |
76 | | -
|
77 | | -: Integer representation of a UUID. Like to `UUID.int`. |
78 | | -
|
79 | | -`x` |
80 | | -
|
81 | | -: Hexadecimal (Base16) representation of a UUID. Like to |
82 | | - `UUID.hex`. |
83 | | -
|
84 | | -`X` |
85 | | -
|
86 | | -: Upper case hexadecimal representation of a UUID. Like to |
87 | | - `UUID.hex`. |
88 | | -
|
89 | | -`base32` |
90 | | -
|
91 | | -: Base32 representation of a UUID without padding. |
92 | | -
|
93 | | -`base64` |
94 | | -
|
95 | | -: Base64 representation of a UUID without padding. |
96 | | -
|
97 | | - :::: warning |
98 | | - ::: title |
99 | | - Warning |
100 | | - ::: |
101 | | -
|
102 | | - Not all file systems support Base64 file names. |
103 | | - :::: |
104 | | -
|
105 | | -All type specifiers also support precisions to cut the string, e.g. |
106 | | -`{{uuid:.2base32}}` would only return the first 2 characters of a |
107 | | -Base32 encoded UUID. |
108 | | -``` |
| 74 | +All type specifiers also support precisions to cut the string, |
| 75 | +e.g. `{{uuid:.2base32}}` would only return the first 2 characters of a Base32 encoded UUID. |
109 | 76 |
|
110 | 77 | ### Type specifiers |
111 | 78 |
|
|
0 commit comments