Allow tagging blog posts
This commit is contained in:
parent
0631d3a672
commit
4fed56630d
2 changed files with 51 additions and 2 deletions
33
project/blog/migrations/0002_auto_20180726_2038.py
Normal file
33
project/blog/migrations/0002_auto_20180726_2038.py
Normal 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'),
|
||||
),
|
||||
]
|
|
@ -1,16 +1,32 @@
|
|||
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 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):
|
||||
body = build_stream_field()
|
||||
|
||||
tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
|
||||
|
||||
search_fields = Entity.search_fields + [
|
||||
index.SearchField('body'),
|
||||
]
|
||||
|
||||
content_panels = Entity.content_panels + [
|
||||
StreamFieldPanel('body'),
|
||||
]
|
||||
FieldPanel('tags')
|
||||
]
|
||||
|
|
Reference in a new issue