blog thumbnails

This commit is contained in:
Christoph J. Scherr 2023-06-04 00:50:03 +02:00
parent 77ad852bf8
commit 08c26ce090
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
8 changed files with 25 additions and 11 deletions

View File

@ -15,6 +15,6 @@ class BlogPost(Searchable):
""" """
body = models.TextField() body = models.TextField()
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True) category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True)
thumbnail = models.ImageField(blank=True) thumbnail = models.ImageField(blank=True, upload_to="img/thumbnails")
public = models.BooleanField(default=True) public = models.BooleanField(default=True)
slug = models.SlugField() slug = models.SlugField()

View File

@ -14,11 +14,12 @@
{% block main %} {% block main %}
<div class="container-xl"> <div class="container-xl">
<div class="jumbotron text-center"> <div class="jumbotron text-center">
<h1>{{ post.title }}</h1> <h1>{{ post.title }} <small class="">{{ post.subtitle }}</small></h1>
<p>{% translate "Blog" %}</p> <img src="{{ post.thumbnail.url }}" alt="thumbnail">
</div> </div>
<div class="container text-center"> <div class="container">
$$x=\frac{-b+\sqrt{b^2-4ac}}{2a}$$ $$x=\frac{-b+\sqrt{b^2-4ac}}{2a}$$
{{ post.body | safe }}
</div> </div>
{% include 'blog/featured.html' %} {% include 'blog/featured.html' %}
</div> </div>

View File

@ -34,15 +34,18 @@ class Post(DetailView):
category__slug=self.kwargs['category'], # first slug is category category__slug=self.kwargs['category'], # first slug is category
slug=self.kwargs['slug'] # second slug is article itself slug=self.kwargs['slug'] # second slug is article itself
) )
logger.debug(obj)
match get_language(): match get_language():
case 'de': case 'de':
logger.debug("returning blogpost for de") logger.debug("setting language unspecific attributes for language: de")
obj['title'] = obj['title_de'] obj.title = obj.title_de
obj.subtitle = obj.subtitle_de
obj.desc = obj.desc_de
case 'en': case 'en':
logger.debug("returning blogpost for en") logger.debug("setting language unspecific attributes for language: en")
obj['title'] = obj['title_en'] obj.title = obj.title_en
obj.subtitle = obj.subtitle_en
obj.desc = obj.desc_en
case _: case _:
# this should not happen, but who knows what dumb stuff users will come up with # this should not happen, but who knows what dumb stuff users will come up with

Binary file not shown.

View File

@ -15,6 +15,7 @@ import os
# default django # default django
from pathlib import Path from pathlib import Path
from django.conf.global_settings import MEDIA_ROOT
from django.utils.log import ServerFormatter from django.utils.log import ServerFormatter
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
@ -288,3 +289,10 @@ LOGGING = {
}, },
} }
# Media stuff
# this is where user uploaded files will go.
# TODO change this for prod
#MEDIA_ROOT = "/home/plex/Documents/code/python/gawa/media"
MEDIA_ROOT = "media/"
MEDIA_URL = "media/"

View File

@ -17,10 +17,12 @@ from django.conf.urls.i18n import i18n_patterns
from django.conf.urls import url from django.conf.urls import url
from django.contrib import admin from django.contrib import admin
from django.urls import include, path from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [ urlpatterns = [
url(r'^i18n/', include('django.conf.urls.i18n')), url(r'^i18n/', include('django.conf.urls.i18n')),
] ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += i18n_patterns( urlpatterns += i18n_patterns(
path("", include("start.urls")), path("", include("start.urls")),

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB