Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-taggit
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7ff1d161
authored
May 03, 2010
by
Carl Meyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
paragraph in README re direct-tagging
parent
f8e0d4d2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
3 deletions
+26
-3
README.txt
+26
-3
No files found.
README.txt
View file @
7ff1d161
...
...
@@ -2,7 +2,7 @@ django-taggit
=============
``django-taggit`` a simpler approach to tagging with Django. Add it to your
``INSTALLED_APPS`` then just add a TaggableManager to your model and go:
``INSTALLED_APPS`` then just add a TaggableManager to your model and go:
:
from django.db import models
...
...
@@ -14,7 +14,7 @@ django-taggit
tags = TaggableManager()
Then you can use the API like so:
Then you can use the API like so:
:
>>> apple = Food.objects.create(name="apple")
>>> apple.tags.add("red", "green", "delicious")
...
...
@@ -26,7 +26,30 @@ Then you can use the API like so:
>>> Food.objects.filter(tags__in=["red"])
[<Food: apple>, <Food: cherry>]
Tags will show up for you automatically in forms and the admin.
If you don't like the inefficiency of generic foreign keys, and you
know in advance which models in your project will be tagged,
django-taggit also supports tagging with direct foreign keys. You must
create your own intermediary model, a subclass of
``taggit.models.TaggedItemBase`` with a foreign key to your content
model named ``content_object``, and then pass this intermediary model
as the ``through`` argument of ``TaggableManager``::
from django.db import models
from taggit.managers import TaggableManager
from taggit.models import TaggedItemBase
class TaggedFood(TaggedItemBase):
content_object = models.ForeignKey('Food')
class Food(models.Model):
# ... fields here
tags = TaggableManager(through=TaggedFood)
Once this is done, the API works identically with direct-tagged or
GFK-tagged models.
``django-taggit`` requires Django 1.1 or greater.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment