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
7ee9fd3a
authored
May 03, 2010
by
Carl Meyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix last failing test; all previous tests pass
parent
a16c126b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
6 deletions
+26
-6
taggit/managers.py
+26
-6
No files found.
taggit/managers.py
View file @
7ee9fd3a
...
...
@@ -27,6 +27,7 @@ class TaggableRel(ManyToManyRel):
class
TaggableManager
(
object
):
def
__init__
(
self
,
verbose_name
=
"Tags"
,
through
=
None
):
self
.
use_gfk
=
through
is
None
self
.
through
=
through
or
TaggedItem
self
.
rel
=
TaggableRel
(
to
=
self
.
through
)
self
.
verbose_name
=
verbose_name
...
...
@@ -100,16 +101,16 @@ class TaggableManager(object):
return
None
def
m2m_reverse_name
(
self
):
try
:
return
self
.
through
.
_meta
.
get_field
(
'content_object'
)
.
rel
.
to
.
_meta
.
pk
.
column
except
FieldDoesNotExist
:
if
self
.
use_gfk
:
return
"id"
else
:
return
self
.
through
.
_meta
.
get_field
(
'content_object'
)
.
rel
.
to
.
_meta
.
pk
.
column
def
m2m_column_name
(
self
):
try
:
return
self
.
through
.
_meta
.
get_field
(
'content_object'
)
.
column
except
FieldDoesNotExist
:
if
self
.
use_gfk
:
return
self
.
through
.
_meta
.
virtual_fields
[
0
]
.
fk_field
else
:
return
self
.
through
.
_meta
.
get_field
(
'content_object'
)
.
column
def
db_type
(
self
,
connection
=
None
):
return
None
...
...
@@ -117,6 +118,16 @@ class TaggableManager(object):
def
m2m_db_table
(
self
):
return
self
.
through
.
_meta
.
db_table
def
extra_filters
(
self
,
pieces
,
pos
,
negate
):
if
negate
or
not
self
.
use_gfk
:
return
[]
prefix
=
"__"
.
join
(
pieces
[:
pos
+
1
])
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
)]
return
self
.
through
.
_meta
.
db_table
class
_TaggableManager
(
models
.
Manager
):
def
__init__
(
self
,
through
=
None
):
...
...
@@ -183,3 +194,12 @@ 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
getattr
(
field
.
field
.
rel
,
"parent_link"
,
None
):
subclasses
.
extend
(
_get_subclasses
(
field
.
model
))
return
subclasses
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