Skip to main content

Simple tagging for the Wagtail CMS.

Project description

Wagtail Taggable

Simple tag functionality for Wagtail sites wanting curated tags without the complexity.

Change Log

  • v0.0.10:
    • Updated InlinePanel invocation to match requirements for Wagtail 4.2 and therefore pin Wagtail 4.2 as the minimum supported version.

Installation & Setup

Install with pip

pip install wagtail-taggable

or

poetry add wagtail-taggable

Add to Django installed apps

INSTALLED_APPS = [
    #...
    'wagtail_taggable',
]

Setup your tag models

Using the register_tag decorator automatically sets up any ForeignKey references to the decorated model to render using a chooser widget specifically for your tag model. It takes care of registering all the form widgets and urls needed to get this interface working.

@register_tag('Example')
class ExampleTag(BaseTag):

    class Meta:
        verbose_name = _('Example')

Optionally expose Tag models using Model Admin

from django.apps import apps
from wagtail.contrib.modeladmin.options import ModelAdmin, ModelAdminGroup

class ExampleTagModelAdmin(ModelAdmin):

    @property
    def model(self):
        return apps.get_model('app.ExampleTag')

    menu_label = 'Example'
    menu_icon = 'tasks'
    menu_order = 100
    list_display = ('name',)


class TagsModelAdminGroup(ModelAdminGroup):

    menu_label = 'Tags'
    menu_icon = 'tag'
    menu_order = 502
    items = [
        ExampleTagModelAdmin,
    ]

from app.admin.tags import TagsModelAdminGroup

modeladmin_register(TagsModelAdminGroup)

Use tags on page models (or any other model)

  1. Define through relationship:

     class ExamplePageExampleTagRelationship(models.Model):
    
         page = ParentalKey(
             'app.ExamplePage',
             on_delete=models.CASCADE,
             related_name='example_tag_relationships',
             related_query_name='example_tag_relationship',
         )
    
         example_tag = models.ForeignKey(
             'app.ExampleTag',
             on_delete=models.CASCADE,
             related_name='example_page_relationships',
             related_query_name='example_page_relationship',
         )
    
  2. Use TagsPanel to render the tags interface in the CMS for the taggable model (in this case a wagtail.Page)

     class ExamplePage(Page):
    
         ...
    
         content_panels = [
             TagsPanel('example_tag_relationships', heading='Example Tags'),
         ]
    

Screenshot

Query items based on tags

Perform queries based on tags like you would with any other related table

tagged_items = (
    ExamplePage.objects
    .filter(example_tag_relationship__example_tag__name='My Cool Tag')
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtail_taggable-0.0.10.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

wagtail_taggable-0.0.10-py2.py3-none-any.whl (8.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file wagtail_taggable-0.0.10.tar.gz.

File metadata

  • Download URL: wagtail_taggable-0.0.10.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for wagtail_taggable-0.0.10.tar.gz
Algorithm Hash digest
SHA256 0745accca9d2dca9b599e6c6208785ed60e9a227e2a786595b2f948d66425235
MD5 a90ac6ffea5d3dc987e3a9c7c1d0dfc1
BLAKE2b-256 64da93a9b6b24689cab6489d2251f00b29d6b66d6178b086c5153ab9de2c431b

See more details on using hashes here.

File details

Details for the file wagtail_taggable-0.0.10-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_taggable-0.0.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ed84610a1a1abe148759ba2945230375435e0147a21135215aab178c6ad118b6
MD5 0bcbffcf255ec933546de154039fb74d
BLAKE2b-256 cd293945d1a3408544f32d3b7a2cb97a95d23f023c002fa8ccc700fcdaec8b0c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page