#47 Settinge of Place Hero Image

This commit is contained in:
2021-04-10 08:23:36 +02:00
parent 2ac39f719f
commit 74d842a668
6 changed files with 73 additions and 8 deletions

View File

@@ -11,6 +11,7 @@ from lostplaces.models.abstract_models import Submittable, Taggable, Mapable
from easy_thumbnails.fields import ThumbnailerImageField
from easy_thumbnails.files import get_thumbnailer
class Place(Submittable, Taggable, Mapable):
"""
Place defines a lost place (location, name, description etc.).
@@ -25,8 +26,31 @@ class Place(Submittable, Taggable, Mapable):
verbose_name=_('Description'),
)
hero = models.ForeignKey(
'PlaceImage',
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name='place_heros'
)
def get_hero_image(self):
if self.hero:
return self.hero
elif len(self.placeimages.all()) > 0:
return self.placeimages.first()
else:
return None
def get_absolute_url(self):
return reverse('place_detail', kwargs={'pk': self.pk})
def get_hero_index_in_queryset(self):
for i in range(0, len(self.placeimages.all())):
image = self.placeimages.all()[i]
if image == self.hero:
return i
return None
@classmethod
@@ -89,7 +113,7 @@ class PlaceImage(PlaceAsset):
upload_to=generate_place_image_filename,
resize_source=dict(size=(2560, 2560),
sharpen=True),
verbose_name=_('Filename(s)'),
verbose_name=_('Images'),
help_text=_('Optional: One or more images to upload')
)
place = models.ForeignKey(
@@ -104,7 +128,7 @@ class PlaceImage(PlaceAsset):
of this image as textual representation of this instance
"""
return 'Image ' + str(self.pk)
return 'Image ' + str(self.place.name)
# These two auto-delete files from filesystem when they are unneeded: