Commit 42b5b22f by Alex Gaynor

Slightly cleaner code.

parent 5eebab39
...@@ -52,12 +52,12 @@ class TaggableManager(RelatedField): ...@@ -52,12 +52,12 @@ class TaggableManager(RelatedField):
models.Field.creation_counter += 1 models.Field.creation_counter += 1
def __get__(self, instance, model): def __get__(self, instance, model):
manager = _TaggableManager(through=self.through)
manager.model = model
if instance is not None and instance.pk is None: if instance is not None and instance.pk is None:
raise ValueError("%s objects need to have a primary key value " raise ValueError("%s objects need to have a primary key value "
"before you can access their tags." % model.__name__) "before you can access their tags." % model.__name__)
manager.instance = instance manager = _TaggableManager(
through=self.through, model=model, instance=instance
)
return manager return manager
def contribute_to_class(self, cls, name): def contribute_to_class(self, cls, name):
...@@ -113,8 +113,10 @@ class TaggableManager(RelatedField): ...@@ -113,8 +113,10 @@ class TaggableManager(RelatedField):
class _TaggableManager(models.Manager): class _TaggableManager(models.Manager):
def __init__(self, through): def __init__(self, through, model, instance):
self.through = through self.through = through
self.model = model
self.instance = instance
def get_query_set(self): def get_query_set(self):
return self.through.tags_for(self.model, self.instance) return self.through.tags_for(self.model, self.instance)
......
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