set a default image for posts

This commit is contained in:
2022-04-08 18:45:31 +00:00
parent a6d37b517e
commit e3e447ed60
2 changed files with 2 additions and 20 deletions

View File

@@ -4,6 +4,7 @@ from datetime import timedelta
from taggit.managers import TaggableManager
from django.conf import settings
from django.contrib.auth.models import User
from django.core.validators import ValidationError
from django.db import models
@@ -259,26 +260,7 @@ class Post(models.Model):
if self.image:
return self.image.url
image = self.find_an_image()
if image:
return image.url
return ""
def find_an_image(self):
"""
find an image via another post
"""
# TODO: Explain why this image is selected on save of the image
# Query all posts that have a slug that equals one of the tags
posts1 = (
Post.objects.filter(slug__in=self.tags.names())
.filter(image__isnull=False)[0:1]
.all()
)
if len(posts1) > 0:
return posts1.get().image
return None
return settings.STATIC_URL + "img/FET-Logo-2014-quadrat.png"
def clean(self):
if self.event_end and self.event_end < self.event_start:

View File

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB