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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
b5fc5d93
authored
Feb 03, 2010
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #7. Corrected tags__in= lookups with inheritance.
parent
4eb17239
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
2 deletions
+26
-2
taggit/managers.py
+13
-1
taggit/tests/models.py
+4
-0
taggit/tests/tests.py
+9
-1
No files found.
taggit/managers.py
View file @
b5fc5d93
...
...
@@ -3,6 +3,7 @@ from collections import defaultdict
import
django
from
django.contrib.contenttypes.models
import
ContentType
from
django.db
import
models
from
django.db.models.related
import
RelatedObject
from
django.db.models.fields.related
import
ManyToManyRel
from
django.db.models.query_utils
import
QueryWrapper
...
...
@@ -106,7 +107,10 @@ class TaggableManager(object):
if
negate
:
return
[]
prefix
=
"__"
.
join
(
pieces
[:
pos
+
1
])
return
[(
"
%
s__content_type"
%
prefix
,
ContentType
.
objects
.
get_for_model
(
self
.
model
))]
cts
=
map
(
ContentType
.
objects
.
get_for_model
,
_get_subclasses
(
self
.
model
))
if
len
(
cts
)
==
1
:
return
[(
"
%
s__content_type"
%
prefix
,
cts
[
0
])]
return
[(
"
%
s__content_type__in"
%
prefix
,
cts
)]
class
_TaggableManager
(
models
.
Manager
):
...
...
@@ -175,3 +179,11 @@ class _TaggableManager(models.Manager):
obj
.
similar_tags
=
result
[
"n"
]
results
.
append
(
obj
)
return
results
def
_get_subclasses
(
model
):
subclasses
=
[
model
]
for
f
in
model
.
_meta
.
get_all_field_names
():
field
=
model
.
_meta
.
get_field_by_name
(
f
)[
0
]
if
isinstance
(
field
,
RelatedObject
)
and
field
.
field
.
rel
.
parent_link
:
subclasses
.
extend
(
_get_subclasses
(
field
.
model
))
return
subclasses
taggit/tests/models.py
View file @
b5fc5d93
...
...
@@ -16,3 +16,6 @@ class Pet(models.Model):
name
=
models
.
CharField
(
max_length
=
50
)
tags
=
TaggableManager
()
class
HousePet
(
Pet
):
trained
=
models
.
BooleanField
()
\ No newline at end of file
taggit/tests/tests.py
View file @
b5fc5d93
...
...
@@ -2,7 +2,7 @@ from django.test import TestCase
from
taggit.models
import
Tag
from
taggit.tests.forms
import
FoodForm
from
taggit.tests.models
import
Food
,
Pet
from
taggit.tests.models
import
Food
,
Pet
,
HousePet
class
BaseTaggingTest
(
TestCase
):
...
...
@@ -65,6 +65,14 @@ class LookupByTagTestCase(BaseTaggingTest):
tag
=
Tag
.
objects
.
get
(
name
=
"woof"
)
self
.
assertEqual
(
list
(
Pet
.
objects
.
filter
(
tags__in
=
[
tag
])),
[
dog
])
cat
=
HousePet
.
objects
.
create
(
name
=
"cat"
,
trained
=
True
)
cat
.
tags
.
add
(
"fuzzy"
)
self
.
assertEqual
(
map
(
lambda
o
:
o
.
pk
,
Pet
.
objects
.
filter
(
tags__in
=
[
"fuzzy"
])),
[
kitty
.
pk
,
cat
.
pk
]
)
class
TaggableFormTestCase
(
BaseTaggingTest
):
def
test_form
(
self
):
...
...
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