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
b2a51255
authored
Jul 03, 2013
by
Florian Apolloner
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #135 from benbacardi/develop
Added names() method to _TaggableManager
parents
57055742
5075638c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
0 deletions
+36
-0
docs/api.txt
+16
-0
taggit/managers.py
+8
-0
tests/tests.py
+12
-0
No files found.
docs/api.txt
View file @
b2a51255
...
@@ -54,6 +54,22 @@ playing around with the API.
...
@@ -54,6 +54,22 @@ playing around with the API.
model with its own tagging through table, only other instances of the
model with its own tagging through table, only other instances of the
same model will be returned.
same model will be returned.
.. method:: names()
Convenience method, returning a ``ValuesListQuerySet`` (basically
just an iterable) containing the name of each tag as a string::
>>> apple.tags.names()
[u'green and juicy', u'red']
.. method:: slugs()
Convenience method, returning a ``ValuesListQuerySet`` (basically
just an iterable) containing the slug of each tag as a string::
>>> apple.slugs.names()
[u'green-and-juicy', u'red']
Filtering
Filtering
~~~~~~~~~
~~~~~~~~~
...
...
taggit/managers.py
View file @
b2a51255
...
@@ -172,6 +172,14 @@ class _TaggableManager(models.Manager):
...
@@ -172,6 +172,14 @@ class _TaggableManager(models.Manager):
self
.
through
.
objects
.
get_or_create
(
tag
=
tag
,
**
self
.
_lookup_kwargs
())
self
.
through
.
objects
.
get_or_create
(
tag
=
tag
,
**
self
.
_lookup_kwargs
())
@require_instance_manager
@require_instance_manager
def
names
(
self
):
return
self
.
get_query_set
()
.
values_list
(
'name'
,
flat
=
True
)
@require_instance_manager
def
slugs
(
self
):
return
self
.
get_query_set
()
.
values_list
(
'slug'
,
flat
=
True
)
@require_instance_manager
def
set
(
self
,
*
tags
):
def
set
(
self
,
*
tags
):
self
.
clear
()
self
.
clear
()
self
.
add
(
*
tags
)
self
.
add
(
*
tags
)
...
...
tests/tests.py
View file @
b2a51255
...
@@ -313,6 +313,18 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
...
@@ -313,6 +313,18 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
self
.
assertTrue
(
hasattr
(
field
,
'related'
))
self
.
assertTrue
(
hasattr
(
field
,
'related'
))
self
.
assertEqual
(
self
.
food_model
,
field
.
related
.
model
)
self
.
assertEqual
(
self
.
food_model
,
field
.
related
.
model
)
def
test_names_method
(
self
):
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
.
tags
.
add
(
'green'
)
apple
.
tags
.
add
(
'red'
)
self
.
assertEqual
(
list
(
apple
.
tags
.
names
()),
[
'green'
,
'red'
])
def
test_slugs_method
(
self
):
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
.
tags
.
add
(
'green and juicy'
)
apple
.
tags
.
add
(
'red'
)
self
.
assertEqual
(
list
(
apple
.
tags
.
slugs
()),
[
'green-and-juicy'
,
'red'
])
class
TaggableManagerDirectTestCase
(
TaggableManagerTestCase
):
class
TaggableManagerDirectTestCase
(
TaggableManagerTestCase
):
food_model
=
DirectFood
food_model
=
DirectFood
...
...
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