diff options
Diffstat (limited to 'askbot/models/tag.py')
-rw-r--r-- | askbot/models/tag.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/askbot/models/tag.py b/askbot/models/tag.py index dfd93879..acfc9413 100644 --- a/askbot/models/tag.py +++ b/askbot/models/tag.py @@ -3,9 +3,9 @@ from django.db import connection, transaction from django.contrib.auth.models import User from django.utils.translation import ugettext as _ from askbot.models.base import DeletableContent +from askbot.models.base import BaseQuerySetManager - -class TagManager(models.Manager): +class TagQuerySet(models.query.QuerySet): UPDATE_USED_COUNTS_QUERY = """ UPDATE tag SET used_count = ( @@ -30,6 +30,18 @@ class TagManager(models.Manager): transaction.commit_unless_managed() + def tags_match_some_wildcard(self, wildcard_tags = None): + """True if any one of the tags in the query set + matches a wildcard + + :arg:`wildcard_tags` is an iterable of wildcard tag strings + """ + for tag in self.all(): + for wildcard_tag in sorted(wildcard_tags): + if tag.name.startswith(wildcard_tag[:-1]): + return True + return False + def get_by_wildcards(self, wildcards = None): """returns query set of tags that match the wildcard tags wildcard tag is guaranteed to end with an asterisk and has @@ -86,6 +98,14 @@ class TagManager(models.Manager): return tags + +class TagManager(BaseQuerySetManager): + """chainable custom filter query set manager + for :class:``~askbot.models.Tag`` objects + """ + def get_query_set(self): + return TagQuerySet(self.model) + class Tag(DeletableContent): name = models.CharField(max_length=255, unique=True) created_by = models.ForeignKey(User, related_name='created_tags') |