Skip to content

Commit cf2d9a8

Browse files
committed
FIX: Make example callback work with multiple blobfields
1 parent e9c1f41 commit cf2d9a8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tests/server/example/models.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from uuid import uuid4
12
from django.db.models import CharField, FileField, Model
23
from 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

6369
class ExampleStorageModel(Model):

0 commit comments

Comments
 (0)