|
UsefulTips
Useful tips for using the tagging application.
Featured Useful TipsSimplifying Tagging With PropertiesThanks to ubernostrum for this tip. When using tags on a model, it's fairly easy to create a simple interface for retrieving and setting them by putting a property on the model: def _get_tags(self):
return Tag.objects.get_for_object(self)
def _set_tags(self, tag_list):
Tag.objects.update_tags(self, tag_list)
tags = property(_get_tags, _set_tags)So suppose you have a blog entry model with tags, and you add the above to it; now you could do: e = Entry.objects.get(pk=12) e.tags # prints the tag list e.tags = 'foo bar' # now the Entry is tagged with 'foo' and 'bar' |
► Sign in to add a comment
Why not make this an actual descriptor? Like,
class FooModel(models.Model): tags = TagManager()It's not strictly a Django manager at that point, but it's a sort of manager.
# And why not to use simply:
from tagging.fields import TagField class SomeModel(models.Model): tags = TagField()To get a list of the tags without hitting the database:
from tagging.utils import parse_tag_input class Object(models.Model): tags = TagField() def get_tag_list(self): return parse_tag_input(self.tags)To my understanding the discussion above is irrelevant with Version 0.3.
The best poker blog http://poker-blogs-see.blogspot.com
Best PokerStars? blog http://pokerstars-blogs.blogspot.com
Sexy, hot girls image http://china-sexy-girl-images.blogspot.com/