Implemented django-thumbs-v2 and modified PlaceOverview template to use scaled images.

This commit is contained in:
Marcus Scholz 2020-07-27 22:53:33 +02:00
parent b027f9d476
commit 912fb8da50
4 changed files with 14 additions and 7 deletions

View File

@ -1 +1,2 @@
django
django-thumbs-v2

View File

@ -38,6 +38,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_thumbs'
]
MIDDLEWARE = [

View File

@ -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,9 +18,14 @@ 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)

View File

@ -7,7 +7,7 @@
<article class="LP-PlaceOverview">
<div class="LP-PlaceOverview__Info">
<img class="LP-PlaceOveriew__Image" src="{{ place.images.first.filename.url }}">
<img class="LP-PlaceOveriew__Image" src="{{ place.images.first.filename.url_hero }}">
<article class="LP-PlaceOverView__Description">
<div class="LP-TextSection">
<h1 class="LP-Headline LP-Headline--main">{{place.name}}</h1>
@ -63,7 +63,7 @@
<ul class="LP-PlaceOverView__ImageList">
{% for place_image in place.images.all %}
<li class="LP-PlaceOverView__ImageItem">
<a href="{{ place_image.filename.url }}"> <img src="{{ place_image.filename.url }}"></a>
<a href="{{ place_image.filename.url_large }}"> <img src="{{ place_image.filename.url_thumbnail }}"></a>
</li>
{% endfor %}
</ul>