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

WIP: trying to get category_create_tests to pass

The last error from running the tests was that the TErm table didnt
exist in the test database. So I'm running

    manage.py makemigrations

And it fails with

    AttributeError: 'NoneType' object has no attribute 'unique'

Following the [django docs](https://docs.djangoproject.com/en/1.8/topics/db/models/#abstract-related-name)
I put in:

        related_name="%(app_label)s_%(class)s_term"

But still can't even get a helpful error message.
parent 3bfb5952
No related branches found
No related tags found
No related merge requests found
......@@ -27,3 +27,7 @@ Item = Message
class Taxonomy(taxonomies.models.Taxonomy):
pass
class Term(taxonomies.models.Term):
pass
......@@ -5,7 +5,7 @@ import pytest
from django.core.urlresolvers import reverse
from rest_framework.test import APIRequestFactory
from data_layer.models import Taxonomy
from data_layer.models import Taxonomy, Term
from ..views import TaxonomyViewSet
......@@ -24,3 +24,24 @@ def test_create_a_category():
assert Taxonomy.objects.count() == 1
[taxonomy] = Taxonomy.objects.all()
assert taxonomy.name == 'Animal'
# TODO: taxonomies have a slug
# TODO: test_get_categories
def add_term(taxonomy, term):
pass
@pytest.mark.django_db
def test_add_term_to_taxonomy():
create_category('Animal')
add_term('Animal', 'dog')
add_term('Animal', 'cat')
[animal] = Taxonomy.objects.all()
terms = Term.objects.all()
assert len(terms) == 2
assert all(term.taxonomy.name == 'Animal' for term in terms)
......@@ -4,6 +4,9 @@ from django.utils.translation import ugettext_lazy as _
class Taxonomy(models.Model):
class Meta:
abstract = True
name = models.CharField(
_('Name'),
max_length=250,
......@@ -34,8 +37,6 @@ class Taxonomy(models.Model):
# To do Categories or limited vocabularies, you use 'optional' and 'admin',
# to do free taggingn use 'multiple' and 'user'
class Meta:
abstract = True
class Term(models.Model):
......@@ -54,6 +55,7 @@ class Term(models.Model):
taxonomy = models.ForeignKey(
Taxonomy,
verbose_name=_('Taxonomy'),
related_name="%(app_label)s_%(class)s_term"
)
long_name = models.TextField(
......
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