Wrong tag query results for models with multiple tags
GoogleCodeExporter opened this issue · comments
Given a model f=Flow() with multiple tags like
f.tags = "asdf ccc"
If I want to retrieve all Tags for Flow that start with "a" I get also
"ccc" which is not what I expected:
In [1]:
Tag.objects.usage_for_queryset(Flow.objects.filter(tags__istartswith='a'))
Out[1]: [<Tag: asdf>, <Tag: ccc>]
In [2]: Tag.objects.usage_for_model(Flow, counts=False,
min_count=None,filters={"tags__istartswith": 'a'})
Out[2]: [<Tag: asdf>, <Tag: ccc>]
Am I missing something here or is this a bug?
Original issue reported on code.google.com by willi.ri...@gmail.com
on 24 Jan 2010 at 2:10
I think you are missing something. I suppose you implemented tags property of
Flow
class yourself, right? And I also suppose this property is of string type,
right? If
I'm right, then Flow.objects.filter(tags__istartswith='a') returns all Flow
objects
whose first letter of Flow.tags property is 'a'. And then
Tag.objects.usage_for_queryset() returns all tags for those Flow objects. So,
I'd say
there's no bug but you using the library the wrong way.
What you want to do could be done like this:
def tags_that_starts_with(str):
foobar = []
for tag in Tag.objects.usage_for_model(Flow):
if tag.startswith(str):
foobar.append(tag)
return foobar
I suppose. I didn't try it out, but I'd say there's no bug here.
Original comment by nskoric@gmail.com
on 26 Jan 2010 at 12:06
- Added labels: ****
- Removed labels: ****