Created
July 21, 2018 19:27
-
-
Save KalobTaulien/ca225bb28e791823eea1c6332e30821b to your computer and use it in GitHub Desktop.
Wagtail 2: Adding Tags to Your Pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Your Django Template --> | |
{% for tag in tags %} | |
<a href="{{ tag.slug }}">{{ tag }}</a> | |
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Adding Tags to your Wagtail Page.""" | |
from modelcluster.fields import ParentalKey | |
from modelcluster.tags import ClusterTaggableManager | |
from taggit.models import TaggedItemBase, Tag | |
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel | |
from wagtail.core.models import Page | |
class StoryTag(TaggedItemBase): | |
"""Through Model for tags.""" | |
content_object = ParentalKey("pages.StoryPage", related_name="tagged_items") | |
class StoryPage(Page): | |
# template = 'templates/story_page.html | |
tags = ClusterTaggableManager( | |
through=StoryTag, | |
blank=False, | |
help_text='Page tags. ie. "Science"', | |
) | |
# Other fields... | |
content_panels = [ | |
# Other panels here | |
MultiFieldPanel([FieldPanel("tags")], heading="Tags"), | |
# More panels here | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment