fixed a bunch of things, hopefully didn't break things

This commit is contained in:
pacnpal
2024-11-05 21:51:02 +00:00
parent 2e8a725933
commit eb5d2acab5
30 changed files with 944 additions and 569 deletions

View File

@@ -27,24 +27,16 @@ def photo_upload_path(instance: models.Model, filename: str) -> str:
if identifier is None:
identifier = obj.pk # Use pk instead of id as it's guaranteed to exist
# Get the next available number for this object
existing_photos = Photo.objects.filter(
content_type=photo.content_type,
object_id=photo.object_id
).count()
next_number = existing_photos + 1
# Create normalized filename
ext = os.path.splitext(filename)[1].lower() or '.jpg' # Default to .jpg if no extension
new_filename = f"{identifier}_{next_number}{ext}"
# Create normalized filename - always use .jpg extension
base_filename = f"{identifier}.jpg"
# If it's a ride photo, store it under the park's directory
if content_type == 'ride':
ride = cast(Ride, obj)
return f"park/{ride.park.slug}/{identifier}/{new_filename}"
return f"park/{ride.park.slug}/{identifier}/{base_filename}"
# For park photos, store directly in park directory
return f"park/{identifier}/{new_filename}"
return f"park/{identifier}/{base_filename}"
class Photo(models.Model):
"""Generic photo model that can be attached to any model"""