From 74a9ee4f391f5f651598a9cb03f31f62a8f1a3c6 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 18 Sep 2020 10:47:00 +0200 Subject: [PATCH] Resize original images, name files with placename in filename, sharpen. --- django_lostplaces/lostplaces/models.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/django_lostplaces/lostplaces/models.py b/django_lostplaces/lostplaces/models.py index 049999e..2cfa5e9 100644 --- a/django_lostplaces/lostplaces/models.py +++ b/django_lostplaces/lostplaces/models.py @@ -144,20 +144,25 @@ class Place(Submittable, Taggable, Mapable): def generate_image_upload_path(instance, filename): """ 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): """ 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. """ 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, on_delete=models.CASCADE,