/django-colortag

Abstract model and utilities to construct colored bootstrap based label buttons.

Primary LanguagePythonMIT LicenseMIT

Django colortag

Tools to help building data tagging models. Used for example in A+ and MOOC-Jutut projects to tag feedbacks or users with colored tags. Project builds on top of Django and django-html5-colorfield.

Installation and usage

Requirements:

Add stuff to requirements.txt:

git+https://github.com/Aalto-LeTech/django-colortag.git@2.0.0#egg=django-colortag==2.0.0

Install them with pip install --process-dependency-links -r requirements.txt (--process-dependency-links is needed, if you don't have js-jquery-toggle in requirements.txt as it's not disributed via pypi).

Add relevant stuff to INSTALLED_APPS:

  • js_jquery_toggle, if you are not using app dependency loading
  • django_colortag

Add something like this to your html header:

<!-- TODO: load bootstrap v3 css -->
<!-- TODO: load jquery -->
<!-- jquery toggle is used by colortag js -->
{% include 'jquery_toggle.head.html' %}
<!-- defines django_colortag_choice js function -->
{% include 'django_colortag.head.html' %}

For bootstrap tooltips to work, you need to do something like this:

$(function() {
  $('.colortag[data-toggle="tooltip"]').tooltip();
  $('.colortag-choice').each(django_colortag_choice); /* only needed if you use ColortagChoiceFilter, ColortagChoiceField or ColortagSelectMultiple */
});

You can render colortag in your templates like this:

{{ tag.render_as_button }}
<!-- or -->
{% load colortag %}
{{ tag|colortag_button }}

For tags to exists, define model like this:

from django_colortag.models import ColorTag

class ItemTag(ColorTag):
    items = models.ManyToManyField(Items, related_name='tags')

You can use colortags in filters like this:

import django_filters
from django_colortag.filters import ColortagChoiceFilter

class TagFilter(django_filters.FilterSet):
    tags = ColortagChoiceFilter()