Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/feuervogel/django-taggit-templatetags
Templatetags for django-taggit.
https://github.com/feuervogel/django-taggit-templatetags
Last synced: 13 days ago
JSON representation
Templatetags for django-taggit.
- Host: GitHub
- URL: https://github.com/feuervogel/django-taggit-templatetags
- Owner: feuervogel
- License: bsd-3-clause
- Created: 2010-07-08T14:35:49.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2011-10-11T12:27:46.000Z (about 13 years ago)
- Last Synced: 2024-08-10T10:56:39.310Z (3 months ago)
- Language: Python
- Homepage:
- Size: 194 KB
- Stars: 146
- Watchers: 11
- Forks: 44
- Open Issues: 16
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.txt
- License: LICENSE.txt
Awesome Lists containing this project
README
============
Instructions
============This is a reusable django app which adds some templatetags to django-taggit_.
Installation
============Just install ``django-taggit-templatetags`` via ``pip``::
$ pip install django-taggit-templatetags
After installing and configuring django-taggit_, just add ``taggit_templatetags`` to your ``INSTALLED_APPS`` in your ``settings.py``::INSTALLED_APPS = (
...
'taggit_templatetags',
...
)
Usage
=====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 ``taggit_extras``::
...
{% load taggit_extras %}
...--------
Taglists
--------After loading ``taggit_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 as tags %}
For the tags of an app, just do::{% get_taglist as tags for 'yourapp' %}
For the tags of an model, just do::{% get_taglist as tags for 'yourapp.yourmodel' %}
No matter what you do, you have a list of tags in the ``tags`` template variable. You can now iterate over it::
- {{tag}} ({{tag.num_times}})
{% for tag in tags %}
{% 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``.
Inclusion-Tag
-------------
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' %}
---------
Tagclouds
---------
A very popular way to navigate through tags is a tagcloud_. This app provides some tags for that::
{% get_tagcloud as tags %}
or::
{% get_tagcloud as tags for 'yourapp' %}
or::
{% 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
-------------
Even for the tagcloud there's an inclusion-tag. For example, for a tagcloud of a model, just do::
{% include_tagcloud 'yourapp.yourmodel' %}
.. _settings:
Settings
========
There are a few settings to be set:
TAGGIT_TAGCLOUD_MIN (default: 1.0)
This specifies the minimum of the weight attribute of a tagcloud's tags.
TAGGIT_TAGCLOUD_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::
{{tag}}
So the weights are converted to integer values.
Thanks
======
Thanks to the python- and django-community, in particular to `Alex Gaynor`_, the inventor of django-taggit_ and a wonderful guy to argue with. Thanks to `Mathijs de Bruin`_ as well for his helpful pull requests.
.. _django-taggit: http://pypi.python.org/pypi/django-taggit
.. _tagcloud: http://www.wikipedia.org/wiki/Tagcloud
.. _Alex Gaynor: http://alexgaynor.net/
.. _Mathijs de Bruin: http://github.com/dokterbob