Commit 8eb936a2 by Alex Gaynor

Fixed a potential issue in a multi-model scenario

parent d513882d
...@@ -139,11 +139,14 @@ class _TaggableManager(models.Manager): ...@@ -139,11 +139,14 @@ class _TaggableManager(models.Manager):
@require_instance_manager @require_instance_manager
def similar_objects(self): def similar_objects(self):
qs = TaggedItem.objects.values('object_id', 'content_type') \ qs = TaggedItem.objects.values('object_id', 'content_type')
.annotate(n=models.Count('pk')) \ qs = qs.annotate(n=models.Count('pk'))
.exclude(object_id=self.object_id) \ qs = qs.exclude(
.filter(tag__in=self.all()) \ object_id=self.object_id,
.order_by('-n') content_type=ContentType.objects.get_for_model(self.model)
)
qs = qs.filter(tag__in=self.all())
qs = qs.order_by('-n')
preload = defaultdict(set) preload = defaultdict(set)
for result in qs: for result in qs:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment