How to use it
Download and place the app's directory somewhere into your project directory,
add it to INSTALLED_APPS in your settings. Also make sure that you have enabled
django.template.loaders.app_directories.load_template_source in the
TEMPLATE_LOADERS setting. This is needed for TagsField to find the template for the
form control.
Add tags to your model:
from myproject.tags.models import Tag
from myproject.tags import fields
class Article(models.Model):
...
tags = fields.TagsField(Tag)
Now you can use the field "tags" the same as the default ManyToManyField. The
only difference is that in forms made with automatic manipulators (including
those in generic views) tags will be displayed as a set of autocomplete
controls (see. included demo.html)
You can include this form field in custom manipulators like this:
from django.forms import Manipulator
from myproject.tags import fields
class MyManipulator(Manipulator):
def __init__(self):
self.fields = [
...
fields.TagsFormField('tags'),
]
Tags are usually stored in the library's built-in Tag model. They are
used for auto-completion in forms. If you use your own model instead of
the default one you should teach a manipulator field to look there:
self.fields = [
...
fields.TagsFormField('tags', model=some.other.TagModel),
]
Settings
In most cases it's enough to set two settings:
JS_URL
- URL to the location where the file "tags.js" is located. You can move it
to your own script directory or leave it in its original location.
STYLE_URL
- URL to the location with the file "tags.css" and graphics.
If these two settings are not set then by default these locations will be
/media/js/ and /media/css/. These are common locations for Django projects.
There's another optional setting: