Giter Site home page Giter Site logo

wagtail-taggable's Introduction

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')
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.