fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Check field limits on picture import.
[wolnelektury.git]
/
apps
/
newtagging
/
models.py
diff --git
a/apps/newtagging/models.py
b/apps/newtagging/models.py
index
3f66681
..
694f5b8
100644
(file)
--- a/
apps/newtagging/models.py
+++ b/
apps/newtagging/models.py
@@
-71,7
+71,7
@@
class TagManager(models.Manager):
if tag not in current_tags:
self.intermediary_table_model._default_manager.create(tag=tag, content_object=obj)
if tag not in current_tags:
self.intermediary_table_model._default_manager.create(tag=tag, content_object=obj)
- tags_updated.send(sender=obj, affected_tags=tags_to_add + tags_for_removal)
+ tags_updated.send(sender=
type(obj), instance=
obj, affected_tags=tags_to_add + tags_for_removal)
def remove_tag(self, obj, tag):
"""
def remove_tag(self, obj, tag):
"""
@@
-104,6
+104,7
@@
class TagManager(models.Manager):
of field lookups to be applied to the given Model as the
``filters`` argument.
"""
of field lookups to be applied to the given Model as the
``filters`` argument.
"""
+ # TODO: Do we really need this filters stuff?
if filters is None: filters = {}
queryset = model._default_manager.filter()
if filters is None: filters = {}
queryset = model._default_manager.filter()
@@
-158,18
+159,15
@@
class TaggedItemManager(models.Manager):
"""
queryset, model = get_queryset_and_model(queryset_or_model)
tags = self.tag_model.get_tag_list(tags)
"""
queryset, model = get_queryset_and_model(queryset_or_model)
tags = self.tag_model.get_tag_list(tags)
- tag_count = len(tags)
- if not tag_count:
+ if not tags:
# No existing tags were given
return queryset.none()
# No existing tags were given
return queryset.none()
- elif tag_count == 1:
- # Optimisation for single tag - fall through to the simpler
- # query below.
- return queryset.filter(tag_relations__tag=tags[0])
# TODO: presumes reverse generic relation
# TODO: presumes reverse generic relation
- return queryset.filter(tag_relations__tag__in=tags
- ).annotate(count=models.Count('pk')).filter(count=len(tags))
+ # Multiple joins are WAY faster than having-count, at least on Postgres 9.1.
+ for tag in tags:
+ queryset = queryset.filter(tag_relations__tag=tag)
+ return queryset
def get_union_by_model(self, queryset_or_model, tags):
"""
def get_union_by_model(self, queryset_or_model, tags):
"""
@@
-181,7
+179,7
@@
class TaggedItemManager(models.Manager):
if not tags:
return queryset.none()
# TODO: presumes reverse generic relation
if not tags:
return queryset.none()
# TODO: presumes reverse generic relation
- return queryset.filter(tag_relations__tag__in=tags)
+ return queryset.filter(tag_relations__tag__in=tags)
.distinct()
def get_related(self, obj, queryset_or_model):
"""
def get_related(self, obj, queryset_or_model):
"""
@@
-230,8
+228,8
@@
def create_intermediary_table_model(model):
class TagMeta(ModelBase):
"Metaclass for tag models (models inheriting from TagBase)."
class TagMeta(ModelBase):
"Metaclass for tag models (models inheriting from TagBase)."
- def __new__(
cl
s, name, bases, attrs):
- model = super(TagMeta,
cls).__new__(cl
s, name, bases, attrs)
+ def __new__(
mc
s, name, bases, attrs):
+ model = super(TagMeta,
mcs).__new__(mc
s, name, bases, attrs)
if not model._meta.abstract:
# Create an intermediary table and register custom managers for concrete models
model.intermediary_table_model = create_intermediary_table_model(model)
if not model._meta.abstract:
# Create an intermediary table and register custom managers for concrete models
model.intermediary_table_model = create_intermediary_table_model(model)