Sunday, 27 October 2013

Tagged under: , , , , ,

DJANGO-TAGGING TUTORIAL



In this post I write a simple django app which uses the django-tagging app. First you need to install django-tagging from this link or you can install it with pip installer using:

pip install django-tagging

Next add 'tagging' to INSTALLED_APPS setting in settings.py. To add tags to a your model say 'Entry' in models.py, you'll need to import a custom field type defined in django-tagging, so add following import statement in yout models.py file:

from tagging.fields import TagField

Next, create the Entry model:

from django.db import models
class Entry(models.Model):
   title = models.CharField(max_length=250)
   slug = models.SlugField(unique_for_date='pub_date') 
   body = models.TextField()
   tags = TagField()

This implements the tagging feature. Next you can setup your views and templates.


0 comments:

Post a Comment