From 912fb8da50e80147130a5246dd7f86d16a11a6da Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Mon, 27 Jul 2020 22:53:33 +0200 Subject: [PATCH] Implemented django-thumbs-v2 and modified PlaceOverview template to use scaled images. --- requirements.txt | 3 ++- source/lostplaces/lostplaces/settings.py | 1 + source/lostplaces/lostplaces_app/models.py | 13 +++++++++---- .../lostplaces_app/templates/placeOverview.html | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index 68d357c..a9c074c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -django \ No newline at end of file +django +django-thumbs-v2 diff --git a/source/lostplaces/lostplaces/settings.py b/source/lostplaces/lostplaces/settings.py index bedc8fd..921a9ca 100644 --- a/source/lostplaces/lostplaces/settings.py +++ b/source/lostplaces/lostplaces/settings.py @@ -38,6 +38,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django_thumbs' ] MIDDLEWARE = [ diff --git a/source/lostplaces/lostplaces_app/models.py b/source/lostplaces/lostplaces_app/models.py index 39c65a4..dc232c6 100644 --- a/source/lostplaces/lostplaces_app/models.py +++ b/source/lostplaces/lostplaces_app/models.py @@ -3,7 +3,7 @@ import uuid from django.db import models from django.dispatch import receiver -from django.utils.translation import ugettext_lazy as _ +from django_thumbs.fields import ImageThumbsField # Create your models here. @@ -18,10 +18,15 @@ class Place (models.Model): return self.name class PlaceImage (models.Model): - filename = models.ImageField( - upload_to=lambda instance, filename: 'places/' + str(uuid.uuid4()), - max_length=50 + filename = ImageThumbsField( + upload_to=lambda instance, filename: 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1], + max_length=50, + sizes = ( + {'code': 'thumbnail', 'wxh': '390x390'}, + {'code': 'hero', 'wxh': '700x700'}, + {'code': 'large', 'wxh': '1920x1920'} ) + ) place = models.ForeignKey(Place, on_delete=models.CASCADE, related_name='images') description = models.TextField(blank=True) diff --git a/source/lostplaces/lostplaces_app/templates/placeOverview.html b/source/lostplaces/lostplaces_app/templates/placeOverview.html index 5770103..4cfcc2d 100644 --- a/source/lostplaces/lostplaces_app/templates/placeOverview.html +++ b/source/lostplaces/lostplaces_app/templates/placeOverview.html @@ -7,7 +7,7 @@
- +

{{place.name}}

@@ -63,7 +63,7 @@
    {% for place_image in place.images.all %}
  • - +
  • {% endfor %}