Commit a38ee9d8 by Florian Apolloner

Merge pull request #213 from nicholasserra/nicholasserra-pluggable-manager

Allow pluggable manager for TaggableManager.
parents 1682de06 a00fbc0a
......@@ -70,6 +70,16 @@ playing around with the API.
>>> apple.tags.slugs()
[u'green-and-juicy', u'red']
.. hint::
You can subclass ``_TaggableManager`` (note the underscore) to add
methods or functionality. ``TaggableManager`` takes an optional
manager keyword argument for your custom class, like this::
class Food(models.Model):
# ... fields here
tags = TaggableManager(manager=_CustomTaggableManager)
Filtering
~~~~~~~~~
......
......@@ -184,3 +184,11 @@ class Article(models.Model):
title = models.CharField(max_length=100)
tags = TaggableManager(through=ArticleTaggedItem)
class CustomManager(models.Model):
class Foo(object):
def __init__(*args, **kwargs):
pass
tags = TaggableManager(manager=Foo)
......@@ -13,14 +13,14 @@ from django.utils.encoding import force_text
from django.contrib.contenttypes.models import ContentType
from taggit.managers import TaggableManager, _model_name
from taggit.managers import TaggableManager, _TaggableManager, _model_name
from taggit.models import Tag, TaggedItem
from .forms import (FoodForm, DirectFoodForm, CustomPKFoodForm,
OfficialFoodForm)
from .models import (Food, Pet, HousePet, DirectFood, DirectPet,
DirectHousePet, TaggedPet, CustomPKFood, CustomPKPet, CustomPKHousePet,
TaggedCustomPKPet, OfficialFood, OfficialPet, OfficialHousePet,
OfficialThroughModel, OfficialTag, Photo, Movie, Article)
OfficialThroughModel, OfficialTag, Photo, Movie, Article, CustomManager)
from taggit.utils import parse_tags, edit_string_for_tags
......@@ -355,7 +355,6 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
'apple': set(['1', '2'])
})
class TaggableManagerDirectTestCase(TaggableManagerTestCase):
food_model = DirectFood
pet_model = DirectPet
......@@ -391,6 +390,16 @@ class TaggableManagerOfficialTestCase(TaggableManagerTestCase):
self.assertEqual(apple, self.food_model.objects.get(tags__official=False))
class TaggableManagerInitializationTestCase(TaggableManagerTestCase):
"""Make sure manager override defaults and sets correctly."""
food_model = Food
custom_manager_model = CustomManager
def test_default_manager(self):
self.assertEqual(self.food_model.tags.__class__, _TaggableManager)
def test_custom_manager(self):
self.assertEqual(self.custom_manager_model.tags.__class__, CustomManager.Foo)
class TaggableFormTestCase(BaseTaggingTestCase):
form_class = FoodForm
......
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