Resize original images, name files with placename in filename, sharpen.

This commit is contained in:
Marcus Scholz 2020-09-18 10:47:00 +02:00
parent b0e775d299
commit 74a9ee4f39

View File

@ -144,20 +144,25 @@ class Place(Submittable, Taggable, Mapable):
def generate_image_upload_path(instance, filename): def generate_image_upload_path(instance, filename):
""" """
Callback for generating path for uploaded images. Callback for generating path for uploaded images.
Returns filename as: placepk-placename{-rndstring}.jpg
""" """
return 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1] return 'places/' + str(instance.place.pk) + '-' + str(instance.place.name) + '.' + filename.split('.')[-1]
class PlaceImage (Submittable): class PlaceImage (Submittable):
""" """
PlaceImage defines an image file object that points to a file in uploads/. PlaceImage defines an image file object that points to a file in uploads/.
Intermediate image sizes are generated as defined in SIZES. Intermediate image sizes are generated as defined in THUMBNAIL_ALIASES.
PlaceImage references a Place to which it belongs. PlaceImage references a Place to which it belongs.
""" """
description = models.TextField(blank=True) description = models.TextField(blank=True)
filename = ThumbnailerImageField(upload_to=generate_image_upload_path) filename = ThumbnailerImageField(
upload_to=generate_image_upload_path,
resize_source=dict(size=(2560, 2560),
sharpen=True)
)
place = models.ForeignKey( place = models.ForeignKey(
Place, Place,
on_delete=models.CASCADE, on_delete=models.CASCADE,