Skip to main content

A generic tagging plugin for Django

Project description

https://travis-ci.org/giginet/django-generic-tagging.svg?branch=master https://coveralls.io/repos/github/giginet/django-generic-tagging/badge.svg?branch=master
Author

giginet <giginet.net@gmail.com>

Supported python versions

3.3, 3.4, 3.5

Supported django versions

Django 1.7 - 1.9

A generic tagging library which enables to attach tags for every objects.

Sample Application

https://django-generic-tagging.herokuapp.com/

Installation

Use pip like:

$ pip install django-generic-tagging

Requirements

Usage

You should refer the example application for detail.

Configuration

  1. Put generic_tagging into your INSTALLED_APPS at settings module

    INSTALLED_APPS = (
       ...
       'generic_tagging',
    )
  2. Add URL patterns into your urls.py

    from django.conf.urls import include, url
    from django.contrib import admin
    
    from generic_tagging.api.routers import TaggingAPIRouter
    
    tagging_router = TaggingAPIRouter(trailing_slash=True)
    
    urlpatterns = [
        ...
        url(r'^tags/', include('generic_tagging.urls')),
        url(r'^api/', include(tagging_router.urls)),
    ]
  3. Create generic_tagging database tables by running:

    $ python manage.py migrate

How to add tagging feature to your model

All you have to do is embed the two template tags into your models’ templates.

  1. Add {% load tagging %} to load tagging module

  2. Place {% render_generic_tagging_head_tag %} into <HEAD> tag

  3. Place {% render_generic_tagging_component_tag_for object %} to where you like.

    {% load tagging %}
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
        {% render_generic_tagging_head_tag %}
        ...
    </head>
    <body>
        <h1>{{ object.title }}</h1>
        {% render_generic_tagging_component_tag_for object %}
    </body>
    </html>

Views

This library has two default views.

Description

Template path

Reversed URL name

Tag list

/templates/generic_tagging/tag_list.html

generic_tagging_tag_list

Tag detail

/templates/generic_tagging/tag_detail.html

generic_tagging_tag_detail

Tag list

This view displays all tags.

templates/generic_tagging/tag_list.html should be used as the template.

<h1>All available tags</h1>
<ul>
    {% for tag in object_list %}
        <li><a href="{{ tag.get_absolute_url %}">{{ tag.label }}</a></li>
    {% endfor %}
</ul>

Tag detail

Each tags have permalinks to display all related objects.

templates/generic_tagging/tag_detail.html should be used as the template.

<h1>All contents relative with {{ object.label }}</h1>
<ul>
    {% for item in object.items.all %}
        <li><a href="{{ item.content_object.get_absolute_url %}">{{ item.content_object }}</a></li>
    {% endfor %}
</ul>

API

django-generic-tagging has REST-ful APIs.

List of API endpoints.

Endpoint

Method

Reversed URL name

/tag/

GET

tag-list

/tagged_item/

GET

tagged_item-list

/tagged_item/<pk>/

GET

tagged_item-detail

/tagged_item/

CREATE

tagged_item-list

/tagged_item/<pk>/

DELETE

tagged_item-detail

/tagged_item/<pk>/lock/

PATCH

tagged_item-lock

/tagged_item/<pk>/unlock/

PATCH

tagged_item-unlock

License

The MIT License (MIT)

Copyright (c) 2016 giginet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

django-generic-tagging-0.0.2.tar.gz (21.3 kB view details)

Uploaded Source

File details

Details for the file django-generic-tagging-0.0.2.tar.gz.

File metadata

File hashes

Hashes for django-generic-tagging-0.0.2.tar.gz
Algorithm Hash digest
SHA256 afa84ae4e4c51d04ca95fbc46eb891771ddb19b1af9ffac61233385930d7a27c
MD5 519cec9fa712f8a435122343bc3e4302
BLAKE2b-256 60c87db56360f6ed887b65aed80e6d5262e6f599ad79de5d65fbb8df6312e12d

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