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
eb39011b
authored
Aug 20, 2010
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get the tests passing
parent
57fca9ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
taggit/managers.py
+8
-2
No files found.
taggit/managers.py
View file @
eb39011b
import
django
import
django
from
django.contrib.contenttypes.generic
import
GenericForeignKey
from
django.contrib.contenttypes.generic
import
GenericForeignKey
,
GenericRelation
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes.models
import
ContentType
from
django.db
import
models
from
django.db
import
models
from
django.db.models.fields.related
import
ManyToManyRel
from
django.db.models.fields.related
import
ManyToManyRel
...
@@ -67,12 +67,18 @@ class TaggableManager(object):
...
@@ -67,12 +67,18 @@ class TaggableManager(object):
self
.
model
=
cls
self
.
model
=
cls
cls
.
_meta
.
add_field
(
self
)
cls
.
_meta
.
add_field
(
self
)
setattr
(
cls
,
name
,
self
)
setattr
(
cls
,
name
,
self
)
if
self
.
use_gfk
:
tagged_items
=
GenericRelation
(
self
.
through
)
tagged_items
.
contribute_to_class
(
cls
,
"tagged_items"
)
def
save_form_data
(
self
,
instance
,
value
):
def
save_form_data
(
self
,
instance
,
value
):
getattr
(
instance
,
self
.
name
)
.
set
(
*
value
)
getattr
(
instance
,
self
.
name
)
.
set
(
*
value
)
def
get_prep_lookup
(
self
,
lookup_type
,
value
):
def
get_prep_lookup
(
self
,
lookup_type
,
value
):
return
models
.
Field
()
.
get_prep_lookup
(
lookup_type
,
value
)
return
models
.
Field
()
.
get_prep_lookup
(
lookup_type
,
value
)
def
get_db_prep_lookup
(
self
,
*
args
,
**
kwargs
):
return
models
.
Field
()
.
get_db_prep_lookup
(
*
args
,
**
kwargs
)
def
formfield
(
self
,
form_class
=
TagField
,
**
kwargs
):
def
formfield
(
self
,
form_class
=
TagField
,
**
kwargs
):
defaults
=
{
defaults
=
{
...
@@ -107,7 +113,7 @@ class TaggableManager(object):
...
@@ -107,7 +113,7 @@ class TaggableManager(object):
def
extra_filters
(
self
,
pieces
,
pos
,
negate
):
def
extra_filters
(
self
,
pieces
,
pos
,
negate
):
if
negate
or
not
self
.
use_gfk
:
if
negate
or
not
self
.
use_gfk
:
return
[]
return
[]
prefix
=
"__"
.
join
(
pieces
[:
pos
+
1
])
prefix
=
"__"
.
join
(
[
"tagged_items"
]
+
pieces
[:
pos
-
2
])
cts
=
map
(
ContentType
.
objects
.
get_for_model
,
_get_subclasses
(
self
.
model
))
cts
=
map
(
ContentType
.
objects
.
get_for_model
,
_get_subclasses
(
self
.
model
))
if
len
(
cts
)
==
1
:
if
len
(
cts
)
==
1
:
return
[(
"
%
s__content_type"
%
prefix
,
cts
[
0
])]
return
[(
"
%
s__content_type"
%
prefix
,
cts
[
0
])]
...
...
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