Skip to content
Snippets Groups Projects
Commit 9e5cffae authored by Mark Skipper's avatar Mark Skipper
Browse files

WIP refactor to use Term.objects.by_taxonomy

parent dff22816
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,23 @@ class Taxonomy(models.Model):
# to do free tagging use 'multiple' and 'open'
class TermManager(models.Manager):
def by_taxonomy(self, taxonomy, term_name):
""" Fetch an existing Term by its name and its
Taxonomy slug which, together should be unique.
"""
if isinstance(taxonomy, basestring):
taxonomy_slug = taxonomy
elif isinstance(taxonomy, Taxonomy):
taxonomy_slug = taxonomy.slug
else:
raise ValueError(
"taxonomy must be a Taxonomy instance "
"or a valid taxonomy slug")
return self.get(taxonomy__slug=taxonomy_slug, name=term_name)
class Term(models.Model):
name = models.CharField(
......@@ -76,6 +93,9 @@ class Term(models.Model):
self.name
)
# Custom Manager
objects = TermManager()
class Meta:
unique_together = ('name', 'taxonomy')
index_together = ['name', 'taxonomy']
from __future__ import unicode_literals, absolute_import
import pytest
from ..models import Term
def test_term_by_taxonomy():
assert False, "Test not written yet"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment