File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 1+ from uuid import uuid4
12from django .db .models import CharField , FileField , Model
23from django_gcp .storage .fields import BlobField
34
@@ -55,9 +56,14 @@ def get_destination_path(
5556 """
5657 # Demonstrate using another field to name the object
5758 category = f"{ instance .category } /" if instance .category is not None else ""
59+
5860 # You may wish to add a timestamp, or random string to prevent collisions
59- # In this case we do the very simple thing of using the original name
60- return f"{ category } { original_name } " , allow_overwrite
61+ # In this case we do the very simple thing of using the original name with random prefix
62+ # If you attempt to overwrite while allow_ovewrite is false, a server error will raise.
63+ # Only set allow_overwrite = True if you really, REALLY, know what you're doing!
64+ random_prefix = str (uuid4 ())[0 :8 ]
65+
66+ return f"{ category } { random_prefix } -{ original_name } " , allow_overwrite
6167
6268
6369class ExampleStorageModel (Model ):
You can’t perform that action at this time.
0 commit comments