📜 ⬆️ ⬇️

Tag Cloud - Django tagging for Django 0.96 # 2

Continuing fiddling with tags .

I did not download Django-tagging 0.2.1, but on the contrary - I took all the best from it and transferred it to version 0.1. Thus, we have a Django 0.96 compatible application with ready-made tools for creating a tag cloud.

You can download from my site (34Kb) . Just unpack the archive into the project folder and add this application to INSTALLED_APPS.
')
# settings.py
...
INSTALLED_APPS = (
...
'myproject.tagging',
)


It is very easy to add tags to any model of your project. For this you need to import from the django-tagging field TagField



# models.py
...
from tagging.fields import TagField

...

class Item (models.Model):
...
tags = TagField ()
...


What I particularly liked about this application is the simplicity and power of using tags in page templates. For example, the following code I use on the main page to display the tag cloud:

# index.html

...

{% tag_cloud_for_model social.Item as item_tags%}

{% for tag in item_tags%}
a href = "" class = "tag" style = "font-size: 1 {{tag.font_size}} pt"
{{tag}}
/ a
{% endfor%}

...


This is an example of displaying all object tags on a page:

# item.html

...

{% tags_for_object recipe as tag_list%}
{% for tag in tag_list%}
a class = "tag" href = ""
{{tag}}
/ a
{% endfor%}

...


Original post in my blog: konkursof.blogspot.com/2008/03/django-tagging-django-096-2.html

Source: https://habr.com/ru/post/21528/


All Articles