1
Fork 0

Allow tagging blog posts

This commit is contained in:
Jake Howard 2018-07-26 21:48:30 +01:00
parent 0631d3a672
commit 4fed56630d
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 51 additions and 2 deletions

View file

@ -0,0 +1,33 @@
# Generated by Django 2.0.7 on 2018-07-26 20:38
from django.db import migrations, models
import django.db.models.deletion
import modelcluster.contrib.taggit
import modelcluster.fields
class Migration(migrations.Migration):
dependencies = [
('taggit', '0002_auto_20150616_2121'),
('blog', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='BlogPageTag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content_object', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='tagged_items', to='blog.BlogPage')),
('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_blogpagetag_items', to='taggit.Tag')),
],
options={
'abstract': False,
},
),
migrations.AddField(
model_name='blogpage',
name='tags',
field=modelcluster.contrib.taggit.ClusterTaggableManager(blank=True, help_text='A comma-separated list of tags.', through='blog.BlogPageTag', to='taggit.Tag', verbose_name='Tags'),
),
]

View file

@ -1,16 +1,32 @@
from project.common.blocks import build_stream_field from project.common.blocks import build_stream_field
from wagtail.admin.edit_handlers import StreamFieldPanel from wagtail.admin.edit_handlers import StreamFieldPanel, FieldPanel
from wagtail.search import index from wagtail.search import index
from project.common.models import Entity from project.common.models import Entity
from django.db import models
from modelcluster.fields import ParentalKey
from modelcluster.contrib.taggit import ClusterTaggableManager
from taggit.models import TaggedItemBase
class BlogPageTag(TaggedItemBase):
content_object = ParentalKey(
'BlogPage',
related_name='tagged_items',
on_delete=models.CASCADE
)
class BlogPage(Entity): class BlogPage(Entity):
body = build_stream_field() body = build_stream_field()
tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
search_fields = Entity.search_fields + [ search_fields = Entity.search_fields + [
index.SearchField('body'), index.SearchField('body'),
] ]
content_panels = Entity.content_panels + [ content_panels = Entity.content_panels + [
StreamFieldPanel('body'), StreamFieldPanel('body'),
] FieldPanel('tags')
]