From 0ee5580c1731db2710eb0e2cddd4abb345bb0ecb Mon Sep 17 00:00:00 2001 From: Jarmil <jarmil.halamicek@seznam.cz> Date: Wed, 14 Oct 2020 15:18:54 +0200 Subject: [PATCH] Weby MS: preskupeni clanku pod stranku clanky; odkaz na autora --- district/models.py | 8 +++--- district/templates/shared/article.html | 2 +- .../migrations/0009_remove_article_author.py | 14 +++++++++++ shared/migrations/0010_article_author.py | 25 +++++++++++++++++++ shared/models.py | 8 +++++- shared/templates/shared/article_preview.html | 2 +- 6 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 shared/migrations/0009_remove_article_author.py create mode 100644 shared/migrations/0010_article_author.py diff --git a/district/models.py b/district/models.py index a853eff4..2ac74131 100644 --- a/district/models.py +++ b/district/models.py @@ -106,7 +106,6 @@ class DistrictHomePage(MetadataPageMixin, Page): ### RELATIONS subpage_types = [ - "shared.Article", "shared.PeoplePage", "DistrictArticles", "DistrictContact", @@ -153,6 +152,10 @@ class DistrictArticles(SharedSubpageMixin, MetadataPageMixin, Page): settings_panels = [] + subpage_types = [ + "shared.Article", + ] + ### OTHERS class Meta: @@ -161,8 +164,7 @@ class DistrictArticles(SharedSubpageMixin, MetadataPageMixin, Page): def get_context(self, request): context = super().get_context(request) context["articles"] = Paginator( - self.get_siblings(inclusive=False).type(Article).live().specific(), - self.max_items or 5, + self.get_children().live().specific(), self.max_items or 5, ).get_page(request.GET.get("page")) return context diff --git a/district/templates/shared/article.html b/district/templates/shared/article.html index 2ba81e80..4b376b60 100644 --- a/district/templates/shared/article.html +++ b/district/templates/shared/article.html @@ -20,7 +20,7 @@ <span class="pr-2">{{ page.last_published_at|date:"SHORT_DATE_FORMAT" }}</span> <span class="pl-2" itemprop="author" itemtype="http://schema.org/Person" itemscope=""> <span itemprop="name"> - <a href="#">{{ page.author }}</a> + <a href="{{ page.author.url }}">{{ page.author }}</a> </span> </span> </div> diff --git a/shared/migrations/0009_remove_article_author.py b/shared/migrations/0009_remove_article_author.py new file mode 100644 index 00000000..b2eab9f3 --- /dev/null +++ b/shared/migrations/0009_remove_article_author.py @@ -0,0 +1,14 @@ +# Generated by Django 3.1.1 on 2020-10-14 13:13 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("shared", "0008_personpage_search_image"), + ] + + operations = [ + migrations.RemoveField(model_name="article", name="author",), + ] diff --git a/shared/migrations/0010_article_author.py b/shared/migrations/0010_article_author.py new file mode 100644 index 00000000..d3ce43b6 --- /dev/null +++ b/shared/migrations/0010_article_author.py @@ -0,0 +1,25 @@ +# Generated by Django 3.1.1 on 2020-10-14 13:13 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("shared", "0009_remove_article_author"), + ] + + operations = [ + migrations.AddField( + model_name="article", + name="author", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="shared.personpage", + verbose_name="Autor článku", + ), + ), + ] diff --git a/shared/models.py b/shared/models.py index d0565053..065513a8 100644 --- a/shared/models.py +++ b/shared/models.py @@ -45,8 +45,14 @@ class Article(SharedSubpageMixin, MetadataPageMixin, Page): null=True, verbose_name="obrázek", ) - author = models.TextField("autor článku", blank=True) tags = ClusterTaggableManager(through=ArticleTag, blank=True) + author = models.ForeignKey( + "shared.PersonPage", + verbose_name="Autor článku", + on_delete=models.PROTECT, + null=True, + blank=True, + ) ### PANELS diff --git a/shared/templates/shared/article_preview.html b/shared/templates/shared/article_preview.html index 73b95c7a..0a46e88a 100644 --- a/shared/templates/shared/article_preview.html +++ b/shared/templates/shared/article_preview.html @@ -33,7 +33,7 @@ <meta itemprop="datePublished" content="{{ article.last_published_at }}" /> </span> <span class="article-card-meta__item" itemprop="author" itemtype="http://schema.org/Person" itemscope=""> - <span itemprop="name">{{ article.author }}</span> + <span itemprop="name">{{ article.author.name }}</span> </span> </div> -- GitLab