@@ -20,9 +20,10 @@ from django.db import models
2020from dynamic_filenames import FilePattern
2121
2222upload_to_pattern = FilePattern(
23- filename_pattern = ' {app_label:.25 } /{model_name:.30 } /{instance.created: %Y-%m-%d} /{uuid: base32}{ext} '
23+ filename_pattern = " {app_label:.25 } /{model_name:.30 } /{instance.created: %Y-%m-%d} /{uuid: base32}{ext} "
2424)
2525
26+
2627class FileModel (models .Model ):
2728 my_file = models.FileField(upload_to = upload_to_pattern)
2829 created = models.DateTimeField(auto_now_add = True )
@@ -36,73 +37,75 @@ Auto slug example:
3637
3738` ext `
3839
39- : File extension including the dot.
40+ : File extension including the dot.
4041
4142` name `
4243
43- : Filename excluding the folders.
44+ : Filename excluding the folders.
4445
4546` model_name `
4647
47- : Name of the Django model.
48+ : Name of the Django model.
4849
4950` app_label `
5051
51- : App label of the Django model.
52+ : App label of the Django model.
5253
5354` instance `
5455
55- : Instance of the model before it has been saved. You may not have a
56- primary key at this point.
56+ : Instance of the model before it has been saved. You may not have a
57+ primary key at this point.
5758
5859` uuid `
5960
60- : UUID version 4 that supports multiple type specifiers. The UUID will
61- be the same should you use it twice in the same string, but
62- different on each invocation of the ` upload_to ` callable.
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.
6364
64- The type specifiers allow you to format the UUID in different ways,
65- e.g. `{uuid:x}` will give you a with a hexadecimal UUID.
65+ ```
66+ The type specifiers allow you to format the UUID in different ways,
67+ e.g. `{uuid:x}` will give you a with a hexadecimal UUID.
6668
67- The supported type specifiers are:
69+ The supported type specifiers are:
6870
69- `s`
71+ `s`
7072
71- : String representation of a UUID including dashes.
73+ : String representation of a UUID including dashes.
7274
73- `i`
75+ `i`
7476
75- : Integer representation of a UUID. Like to `UUID.int`.
77+ : Integer representation of a UUID. Like to `UUID.int`.
7678
77- `x`
79+ `x`
7880
79- : Hexadecimal (Base16) representation of a UUID. Like to
80- `UUID.hex`.
81+ : Hexadecimal (Base16) representation of a UUID. Like to
82+ `UUID.hex`.
8183
82- `X`
84+ `X`
8385
84- : Upper case hexadecimal representation of a UUID. Like to
85- `UUID.hex`.
86+ : Upper case hexadecimal representation of a UUID. Like to
87+ `UUID.hex`.
8688
87- `base32`
89+ `base32`
8890
89- : Base32 representation of a UUID without padding.
91+ : Base32 representation of a UUID without padding.
9092
91- `base64`
93+ `base64`
9294
93- : Base64 representation of a UUID without padding.
95+ : Base64 representation of a UUID without padding.
9496
95- :::: warning
96- ::: title
97- Warning
98- :::
97+ :::: warning
98+ ::: title
99+ Warning
100+ :::
99101
100- Not all file systems support Base64 file names.
101- ::::
102+ Not all file systems support Base64 file names.
103+ ::::
102104
103- All type specifiers also support precisions to cut the string, e.g.
104- `{{uuid:.2base32}}` would only return the first 2 characters of a
105- Base32 encoded UUID.
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+ ```
106109
107110### Type specifiers
108111
@@ -115,9 +118,10 @@ from django.db import models
115118from dynamic_filenames import FilePattern
116119
117120upload_to_pattern = FilePattern(
118- filename_pattern = ' {app_label:.25 } /{model_name:.30 } /{instance.title: .40slug}{ext} '
121+ filename_pattern = " {app_label:.25 } /{model_name:.30 } /{instance.title: .40slug}{ext} "
119122)
120123
124+
121125class FileModel (models .Model ):
122126 title = models.CharField(max_length = 100 )
123127 my_file = models.FileField(upload_to = upload_to_pattern)
0 commit comments