aboutsummaryrefslogtreecommitdiff
path: root/tagging/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'tagging/models.py')
-rw-r--r--tagging/models.py48
1 files changed, 13 insertions, 35 deletions
diff --git a/tagging/models.py b/tagging/models.py
index 7463ddb..d43f22d 100644
--- a/tagging/models.py
+++ b/tagging/models.py
@@ -16,15 +16,9 @@ from django.utils.translation import ugettext_lazy as _
from tagging import settings
from tagging.utils import calculate_cloud, get_tag_list, get_queryset_and_model, parse_tag_input
from tagging.utils import LOGARITHMIC
-from tagging.validators import isTag
qn = connection.ops.quote_name
-try:
- from django.db.models.query import parse_lookup
-except ImportError:
- parse_lookup = None
-
############
# Managers #
############
@@ -147,23 +141,10 @@ class TagManager(models.Manager):
"""
if filters is None: filters = {}
- if not parse_lookup:
- # post-queryset-refactor (hand off to usage_for_queryset)
- queryset = model._default_manager.filter()
- for f in filters.items():
- queryset.query.add_filter(f)
- usage = self.usage_for_queryset(queryset, counts, min_count)
- else:
- # pre-queryset-refactor
- extra_joins = ''
- extra_criteria = ''
- params = []
- if len(filters) > 0:
- joins, where, params = parse_lookup(filters.items(), model._meta)
- extra_joins = ' '.join(['%s %s AS %s ON %s' % (join_type, table, alias, condition)
- for (alias, (table, join_type, condition)) in joins.items()])
- extra_criteria = 'AND %s' % (' AND '.join(where))
- usage = self._get_usage(model, counts, min_count, extra_joins, extra_criteria, params)
+ queryset = model._default_manager.filter()
+ for f in filters.items():
+ queryset.query.add_filter(f)
+ usage = self.usage_for_queryset(queryset, counts, min_count)
return usage
@@ -180,8 +161,6 @@ class TagManager(models.Manager):
greater than or equal to ``min_count`` will be returned.
Passing a value for ``min_count`` implies ``counts=True``.
"""
- if parse_lookup:
- raise AttributeError("'TagManager.usage_for_queryset' is not compatible with pre-queryset-refactor versions of Django.")
extra_joins = ' '.join(queryset.query.get_from_clause()[0][1:])
where, params = queryset.query.where.as_sql()
@@ -288,7 +267,7 @@ class TaggedItemManager(models.Manager):
objects we're interested in, then use the ORM's ``__in``
lookup to return a ``QuerySet``.
- Once the queryset-refactor branch lands in trunk, this can be
+ Now that the queryset-refactor branch is in the trunk, this can be
tidied up significantly.
"""
def get_by_model(self, queryset_or_model, tags):
@@ -440,11 +419,16 @@ class TaggedItemManager(models.Manager):
'tag': qn(self.model._meta.get_field('tag').rel.to._meta.db_table),
'content_type_id': content_type.pk,
'related_content_type_id': related_content_type.pk,
- 'limit_offset': num is not None and connection.ops.limit_offset_sql(num) or '',
+ # Hardcoding this for now just to get tests working again - this
+ # should now be handled by the query object.
+ 'limit_offset': num is not None and 'LIMIT %s' or '',
}
cursor = connection.cursor()
- cursor.execute(query, [obj.pk])
+ params = [obj.pk]
+ if num is not None:
+ params.append(num)
+ cursor.execute(query, params)
object_ids = [row[0] for row in cursor.fetchall()]
if len(object_ids) > 0:
# Use in_bulk here instead of an id__in lookup, because id__in would
@@ -463,7 +447,7 @@ class Tag(models.Model):
"""
A tag.
"""
- name = models.CharField(_('name'), max_length=50, unique=True, db_index=True, validator_list=[isTag])
+ name = models.CharField(_('name'), max_length=50, unique=True, db_index=True)
objects = TagManager()
@@ -472,9 +456,6 @@ class Tag(models.Model):
verbose_name = _('tag')
verbose_name_plural = _('tags')
- class Admin:
- pass
-
def __unicode__(self):
return self.name
@@ -495,8 +476,5 @@ class TaggedItem(models.Model):
verbose_name = _('tagged item')
verbose_name_plural = _('tagged items')
- class Admin:
- pass
-
def __unicode__(self):
return u'%s [%s]' % (self.object, self.tag)