Skip to main content

Repackaging django-taggit with add-ons

Project description


An app for managing tags largely built on `django-taggit <>`_
We integrated in this package two other add-ons for taggit :
- `django-taggit-autosuggest <>`_
- `django-taggit-templatetags <>`_

So we have a nice styled autocomplete widget and some templatetags to use taggit.
Tag slugs are unicode-friendly. That means accented letters are valid URI characters (like they should be !)
So you can have differents slugs for differents tags.

Installation and dependencies::
$ pip install git+git://
$ pip install django-autoslug
$ pip install unicode-slugify
$ pip install coop_tag

Add `coop_tag` (with an underscore) to INSTALLED_APPS in your django project settings.
Run `python collectstatic` in your django project directory.
Add the following line a the bottom of your project's file::
(r'^', include('coop_tag.urls')),


To enable Tags, just let the tagged model use the TaggableManager::

from django.db import models
from coop_tag.managers import TaggableManager

class SomeModel(models.Model):
tags = TaggableManager(help_text="your optional help text", blank=True,)

If you want to leverage Generic Relations, you can use a `through` model::

from coop_tag.managers import TaggableManager
from coop_tag.models import TaggedItem

class SomeModel(models.Model):
tags = TaggableManager(through=TaggedItem, blank=True,)

The Tag model and the optional TaggedItem model are configurable, you can use your owns (see seetings above)

You can use the great taggit API like so::

>>> apple = Food.objects.create(name="apple")
>>> apple.tags.add("red", "green", "delicious")
>>> apple.tags.all()
[<Tag: red>, <Tag: green>, <Tag: delicious>]
>>> apple.tags.remove("green")
>>> apple.tags.all()
[<Tag: red>, <Tag: delicious>]
>>> Food.objects.filter(tags__name__in=["red"])
[<Food: apple>, <Food: cherry>]

Tags will show up for you automatically in forms and the admin.

Template tags

Fork of `django-taggit-templatetags`, a reusable django app which adds some templatetags to django-taggit_.
This particular fork uses a fork of django-templatetag-sugar_, by Jonas Geiregat, only this version allows us to give multiples arguments to a templatetag.

Now there are some templatetags enabled, at the moment only to create lists of tags and tag-clouds.
In your templates, you need to load ``tagger_extras``::

{% load tagger_extras %}


After loading ``tagger_extras`` you can create a list of tags for the whole project (in the sense of djangoproject), for an app (in the sense of djangoapp), for a model-class (to get a list for an instance of a model, just use its tag-field).

For the tags of a project, just do::

{% get_taglist asvar tags %}

To limit the number of tags::

{% get_taglist asvar tags count 25 %}

For the tags of an app, just do::

{% get_taglist asvar tags for_obj 'yourapp' %}

For the tags of a model, just do::

{% get_taglist asvar tags for_obj 'yourapp.yourmodel' %}

You can also customize the name of the tags manager in your model (the default is *tags*)::

{% get_taglist asvar tags for_obj 'yourapp.yourmodel:yourtags' %}

No matter what you do, you have a list of tags in the ``tags`` template variable. You can now iterate over it::

<ul id="tags" class="indextags">
{% get_taglist asvar all_tags for_obj target_app count 15 %}
{% for tag in all_tags %}
<li class="tag">
<a href="{{ tag.get_absolute_url }}">{{tag}} ({{tag.num_times}})</a>
{% endfor %}

As you can see, each tag has an attribute ``num_times`` which declares how many times it was used. The list of tags is sorted descending by ``num_times``.


For convenience, there's an inclusion-tag. It's used analogue. For example, for a taglist of a model, just do::

{% include_taglist 'yourapp.yourmodel' %}


A very popular way to navigate through tags is a tagcloud_. This app provides some tags for that::

{% get_tagcloud as tags %}


{% get_tagcloud as tags for 'yourapp' %}


{% get_tagcloud as tags for 'yourapp.yourmodel' %}

respectivly. The resulting list of tags is ordered by their ``name`` attribute. Besides the ``num_items`` attribute, there's a ``weight`` attribute. Its maximum and minimum may be specified as the settings_ section reads.

Inclusion-Tag in Tagcloud

Even for the tagcloud there's an inclusion-tag. For example, for a tagcloud of a model, just do::

{% include_tagcloud 'yourapp.yourmodel' %}

.. _settings:

Optional Settings

TAGGER_TAG_MODEL (Defaults to 'coop_tag.models.Tag')
The Tag model used, if you happen to use a custom model.
TAGGER_TAGGEDITEM_MODEL (Defaults to 'coop_tag.models.TaggedItem')
The Taggeditem model used, if you happen to use a custom model.
TAGGER_FKEY_NAME (Defaults to 'coop_local.Tag')
The linked model on the through model can also be customized (use only if you have the two settings above set)

Instead of collecting and serving the static files directly, you can also set this variable to your static base URL somewhere else.
TAGGER_CSS_FILENAME (Defaults to 'coop_tag.css'):
Set the CSS file which best fits your site elements.
The amount of suggestions is limited, you can raise or lower the limit of default 20 using this setting
TAGGER_CLOUD_MIN (default: 1.0)
This specifies the minimum of the weight attribute of a tagcloud's tags.
TAGGER_CLOUD_MAX (default: 6.0)
This specifies the maximum of the weight attribute of a tagcloud's tags.

If you want to use the weight as font-sizes, just do as follows::

<font size={{tag.weight|floatformat:0}}>{{tag}}</font>

So the weights are converted to integer values.

.. _django-templatetag-sugar :
.. _django-taggit:

*** Credits ***
This project is directly based on those projects:
* Alex Gaynor
* Ludwik Trammer:
* Jeremy Epstein:
* Flavio Curella:
* Drew Wilson:
* Mathijs de Bruin:

coop-tag uses the same license as Django (BSD).
coop-tag development is currently funded by `CREDIS <>`_, FSE (European Social Fund) and `Conseil Regional Auvergne <>`_.

Project details

Download files

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

Files for coop-tag, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size coop-tag-0.2.1.tar.gz (32.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page