keywords are created

This commit is contained in:
Christoph J. Scherr 2023-10-02 00:56:26 +02:00
parent adac986018
commit b269b452fd
1 changed files with 10 additions and 2 deletions

View File

@ -5,7 +5,7 @@ import pathlib
import markdown import markdown
from django.db import models from django.db import models
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from start.models import Searchable from start.models import Keyword, Searchable
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -129,7 +129,15 @@ class BlogPost(Searchable):
logger.debug(f"category of {self}: {category}") logger.debug(f"category of {self}: {category}")
self.category = 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: except Exception as e:
logger.warning( logger.warning(