Summary: calling Tags.object.usage_for_queryset(qset) corrupts the qset and
also produces the same output as getting all tags for a model.
Try the following (must have a model with tags, have imported Tag, TaggedItem):
# get a queryset of DinerModel objects tagged with 'chinese'
>>> foundDiners = TaggedItem.objects.get_by_model(DinerModel, 'chinese')
>>> foundDiners
[<DinerModel: Mandarin Grill>, <DinerModel: NANO Grill>]
# Attempt to get a list/set of tags shared between models in the queryset
>>> foundTags = Tag.objects.usage_for_queryset(foundDiners)
# Now if you display foundTags, it will be a list/set of ALL tags used by
# DinerModel, not a list/set of only the tags used in the foundDiners
# queryset.
# Example: (filtering on the set of restaurants tagged with Chinese should
# not have pizza, italian, etc, tags. There are no Chinese restaurants
# tagged with pizza.)
>>> foundTags
[<Tag: bar>, <Tag: catering>, <Tag: chinese>, <Tag: delivery>, <Tag:
happy_hour>, <Tag: italian>, <Tag: near_campus>, <Tag: pizza>, <Tag:
specials>, <Tag: take_out>]
# Now for the BIG problematic error, call foundDiners to display it again
# Giant error output. Somehow filtering by queryset not only returns the \
# same thing as getting tags for the model, it destroys the original
# queryset to be used as a filter.
>>> foundDiners
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line
55, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line
70, in __len__
self._result_cache.extend(list(self._iter))
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line
193, in iterator
for row in self.query.results_iter():
File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py",
line 262, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py",
line 2273, in execute_sql
sql, params = self.as_sql()
File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py",
line 371, in as_sql
out_cols = self.get_columns(with_col_aliases)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py",
line 701, in get_columns
col_aliases)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py",
line 768, in get_default_columns
table = self.alias_map[alias][TABLE_NAME]
KeyError: 'tagging_taggeditem'
Original issue reported on code.google.com by sand...@wildcat.arizona.edu on 29 Jul 2009 at 6:53
Original issue reported on code.google.com by
sand...@wildcat.arizona.edu
on 29 Jul 2009 at 6:53