Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-taggit
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
daaf93d3
authored
Dec 08, 2009
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SUpport lookups by Tag object.
parent
90fe33b7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
taggit/managers.py
+12
-2
taggit/tests/tests.py
+3
-0
No files found.
taggit/managers.py
View file @
daaf93d3
...
...
@@ -48,8 +48,18 @@ class TaggableManager(object):
raise
ValueError
(
"You can't do lookups other than
\"
in
\"
and
\"
exact
\"
on Tags"
)
if
lookup_type
==
"exact"
:
value
=
[
value
]
qs
=
TaggedItem
.
objects
.
filter
(
tag__name__in
=
value
)
.
values_list
(
"pk"
,
flat
=
True
)
sql
,
params
=
qs
.
query
.
as_sql
()
if
all
(
isinstance
(
v
,
Tag
)
for
v
in
value
):
qs
=
TaggedItem
.
objects
.
filter
(
tag__in
=
value
)
elif
all
(
isinstance
(
v
,
basestring
)
for
v
in
value
):
qs
=
TaggedItem
.
objects
.
filter
(
tag__name__in
=
value
)
elif
all
(
isinstance
(
v
,
int
)
for
v
in
value
):
# This one is really ackward, just don't do it. The ORM does it
# for deletes, but no one else gets to.
qs
=
TaggedItem
.
objects
.
filter
(
pk__in
=
value
)
else
:
# Fucking flip-floppers.
raise
ValueError
(
"You can't combine Tag objects and strings, pick one!"
)
sql
,
params
=
qs
.
values_list
(
"pk"
,
flat
=
True
)
.
query
.
as_sql
()
return
QueryWrapper
((
"(
%
s)"
%
sql
),
params
)
def
related_query_name
(
self
):
...
...
taggit/tests/tests.py
View file @
daaf93d3
...
...
@@ -54,6 +54,9 @@ class LookupByTagTestCase(BaseTaggingTest):
self
.
assertEqual
(
list
(
Food
.
objects
.
filter
(
tags__in
=
[
"red"
])
.
distinct
()),
[
apple
])
self
.
assertEqual
(
list
(
Food
.
objects
.
filter
(
tags
=
"red"
)
.
distinct
()),
[
apple
])
tag
=
Tag
.
objects
.
get
(
name
=
"woof"
)
self
.
assertEqual
(
list
(
Pet
.
objects
.
filter
(
tags
=
tag
)),
[
dog
])
class
TaggableFormTestCase
(
BaseTaggingTest
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment