diff options
author | Jonathan DeMasi <jrdemasi@gmail.com> | 2020-03-02 22:00:47 -0700 |
---|---|---|
committer | Jonathan DeMasi <jrdemasi@gmail.com> | 2020-03-02 22:00:47 -0700 |
commit | bca608ecb1332fdb738ea53305e93ca08b4a211c (patch) | |
tree | 72528ec4eb3e87b21ed4bea8626a2e4f7bf54258 | |
parent | 7078ade87556b727f4ff1183b0a2ea240f0ad9f4 (diff) | |
download | jthanio-bca608ecb1332fdb738ea53305e93ca08b4a211c.tar jthanio-bca608ecb1332fdb738ea53305e93ca08b4a211c.tar.gz jthanio-bca608ecb1332fdb738ea53305e93ca08b4a211c.tar.bz2 jthanio-bca608ecb1332fdb738ea53305e93ca08b4a211c.tar.lz jthanio-bca608ecb1332fdb738ea53305e93ca08b4a211c.tar.xz jthanio-bca608ecb1332fdb738ea53305e93ca08b4a211c.tar.zst jthanio-bca608ecb1332fdb738ea53305e93ca08b4a211c.zip |
well we're getting somewhere with categories
-rw-r--r-- | blog/migrations/0005_blogpost_categories.py | 19 | ||||
-rw-r--r-- | blog/models.py | 7 | ||||
-rw-r--r-- | blog/templates/blog/blog_post.html | 5 |
3 files changed, 27 insertions, 4 deletions
diff --git a/blog/migrations/0005_blogpost_categories.py b/blog/migrations/0005_blogpost_categories.py new file mode 100644 index 0000000..92fb47e --- /dev/null +++ b/blog/migrations/0005_blogpost_categories.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.3 on 2020-03-03 04:44 + +from django.db import migrations +import modelcluster.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0004_blogcategory'), + ] + + operations = [ + migrations.AddField( + model_name='blogpost', + name='categories', + field=modelcluster.fields.ParentalManyToManyField(blank=True, to='blog.BlogCategory'), + ), + ] diff --git a/blog/models.py b/blog/models.py index fb9c828..8301fed 100644 --- a/blog/models.py +++ b/blog/models.py @@ -1,10 +1,11 @@ from django.db import models +from django import forms from wagtail.core.models import Page, Orderable from wagtail.core.fields import RichTextField from wagtail.admin.edit_handlers import FieldPanel, InlinePanel, MultiFieldPanel from wagtail.search import index -from modelcluster.fields import ParentalKey +from modelcluster.fields import ParentalKey, ParentalManyToManyField from modelcluster.contrib.taggit import ClusterTaggableManager from taggit.models import TaggedItemBase from wagtail.snippets.models import register_snippet @@ -36,6 +37,7 @@ class BlogPost(Page): intro = models.CharField(max_length=250) body = RichTextField(blank=True) tags = ClusterTaggableManager(through=BlogPostTag, blank=True) + categories = ParentalManyToManyField('blog.BlogCategory', blank=True) search_fields = Page.search_fields + [ index.SearchField('intro'), @@ -46,9 +48,10 @@ class BlogPost(Page): MultiFieldPanel([ FieldPanel('date'), FieldPanel('tags'), + FieldPanel('categories', widget=forms.CheckboxSelectMultiple), ], heading="Blog information"), FieldPanel('intro'), - FieldPanel('body'), + FieldPanel('body') ] class BlogTagIndexPage(Page): diff --git a/blog/templates/blog/blog_post.html b/blog/templates/blog/blog_post.html index 9a2f318..f65bce1 100644 --- a/blog/templates/blog/blog_post.html +++ b/blog/templates/blog/blog_post.html @@ -15,8 +15,9 @@ <!-- Title --> <h1 class="mt-4">{{ page.title }}</h1> <!-- Date/Time --> - <p>Posted on {{ page.date }} in CATEGORY</p> - + {% with categories=page.categories.all %} + <p>Posted on {{ page.date }}{% if categories %} in {% for category in categories %}{{ category.name }}, {% endfor %} {% endif %}</p> + {% endwith %} <hr> <!-- Preview Image --> |