Skip to content

Commit

Permalink
Added the generic foreign key query trick to the tag_detail page, try…
Browse files Browse the repository at this point in the history
…ing to reduce queries there as well. Fixes #20.
  • Loading branch information
palewire committed Oct 8, 2011
1 parent 9a8b8c9 commit 7477fbd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions coltrane/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def tag_detail(request, tag):
raise Http404

# Pull all the items with that tag.
taggeditem_list = tag.items.all()
taggeditem_list = TaggedItem.objects.filter(tag=tag).fetch_generic_relations()

# Loop through the tagged items and return just the items
object_list = [i.object for i in taggeditem_list if getattr(i.object, 'pub_date', False)]

Expand Down
1 change: 0 additions & 1 deletion tagging/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""
from django.contrib.contenttypes.models import ContentType
from django.db import models

from tagging.models import Tag, TaggedItem

class ModelTagManager(models.Manager):
Expand Down
6 changes: 4 additions & 2 deletions tagging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.db import connection, models
from django.db.models.query import QuerySet
from django.utils.translation import ugettext_lazy as _

from coltrane.managers import GFKQuerySet
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
Expand Down Expand Up @@ -277,6 +277,9 @@ class TaggedItemManager(models.Manager):
Now that the queryset-refactor branch is in the trunk, this can be
tidied up significantly.
"""
def get_query_set(self):
return GFKQuerySet(self.model)

def get_by_model(self, queryset_or_model, tags):
"""
Create a ``QuerySet`` containing instances of the specified
Expand Down Expand Up @@ -474,7 +477,6 @@ class TaggedItem(models.Model):
content_type = models.ForeignKey(ContentType, verbose_name=_('content type'))
object_id = models.PositiveIntegerField(_('object id'), db_index=True)
object = generic.GenericForeignKey('content_type', 'object_id')

objects = TaggedItemManager()

class Meta:
Expand Down

0 comments on commit 7477fbd

Please sign in to comment.