From b269b452fd773d1fb07486cc54d98fbdb70da008 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Mon, 2 Oct 2023 00:56:26 +0200 Subject: [PATCH] keywords are created --- gawa/blog/models.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gawa/blog/models.py b/gawa/blog/models.py index 3dc3c88..cffb4ea 100644 --- a/gawa/blog/models.py +++ b/gawa/blog/models.py @@ -5,7 +5,7 @@ import pathlib import markdown from django.db import models from django.utils.translation import gettext as _ -from start.models import Searchable +from start.models import Keyword, Searchable import logging logger = logging.getLogger(__name__) @@ -129,7 +129,15 @@ class BlogPost(Searchable): logger.debug(f"category of {self}: {category}") self.category = category - self.keywords = None + for item in meta_en["keywords"]: + try: + keyword: Keyword = Keyword.objects.get( + slug=item) + except Keyword.DoesNotExist: + keyword = Keyword.objects.create( + slug=item, text_en=item, text_de=item) + logger.debug(f"keywords of '{self}': {self.keywords}") + except Exception as e: logger.warning(