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
fdcce8d0
authored
Dec 08, 2009
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
You can add tag objects.
parent
2172cc0b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
0 deletions
+4
-0
taggit/managers.py
+1
-0
taggit/tests/tests.py
+3
-0
No files found.
taggit/managers.py
View file @
fdcce8d0
...
@@ -105,6 +105,7 @@ class _TaggableManager(models.Manager):
...
@@ -105,6 +105,7 @@ class _TaggableManager(models.Manager):
@require_instance_manager
@require_instance_manager
def
add
(
self
,
*
tags
):
def
add
(
self
,
*
tags
):
for
tag
in
tags
:
for
tag
in
tags
:
if
not
isinstance
(
tag
,
Tag
):
tag
,
_
=
Tag
.
objects
.
get_or_create
(
name
=
tag
)
tag
,
_
=
Tag
.
objects
.
get_or_create
(
name
=
tag
)
TaggedItem
.
objects
.
create
(
object_id
=
self
.
object_id
,
TaggedItem
.
objects
.
create
(
object_id
=
self
.
object_id
,
content_type
=
ContentType
.
objects
.
get_for_model
(
self
.
model
),
tag
=
tag
)
content_type
=
ContentType
.
objects
.
get_for_model
(
self
.
model
),
tag
=
tag
)
...
...
taggit/tests/tests.py
View file @
fdcce8d0
...
@@ -34,6 +34,9 @@ class AddTagTestCase(BaseTaggingTest):
...
@@ -34,6 +34,9 @@ class AddTagTestCase(BaseTaggingTest):
apple
.
tags
.
remove
(
'green'
)
apple
.
tags
.
remove
(
'green'
)
self
.
assert_tags_equal
(
apple
.
tags
.
all
(),
[
'red'
])
self
.
assert_tags_equal
(
apple
.
tags
.
all
(),
[
'red'
])
self
.
assert_tags_equal
(
Food
.
tags
.
all
(),
[
'green'
,
'red'
])
self
.
assert_tags_equal
(
Food
.
tags
.
all
(),
[
'green'
,
'red'
])
tag
=
Tag
.
objects
.
create
(
name
=
"delicious"
)
apple
.
tags
.
add
(
tag
)
self
.
assert_tags_equal
(
apple
.
tags
.
all
(),
[
"red"
,
"delicious"
])
class
LookupByTagTestCase
(
BaseTaggingTest
):
class
LookupByTagTestCase
(
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