Commit 5075638c by Ben Cardy

Added slugs method and tests

parent 62d88910
......@@ -60,9 +60,15 @@ playing around with the API.
just an iterable) containing the name of each tag as a string::
>>> apple.tags.names()
[u'green', u'red']
>>> 'green' in apple.tags.names()
True
[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
~~~~~~~~~
......
......@@ -176,6 +176,10 @@ class _TaggableManager(models.Manager):
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):
self.clear()
self.add(*tags)
......
......@@ -319,6 +319,12 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
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):
food_model = DirectFood
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment