Skip to content
Snippets Groups Projects
Commit d55d152f authored by Martin Burchell's avatar Martin Burchell
Browse files

Added vocabulary field to Taxonomy

parent 08d4c49d
No related branches found
No related tags found
1 merge request!44Added multiplicity field to Taxonomy
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('taxonomies', '0003_taxonomy_multiplicity'),
]
operations = [
migrations.AddField(
model_name='taxonomy',
name='vocabulary',
field=models.CharField(default=b'closed', max_length=30, choices=[(b'fixed', 'Not modifiable by any user, system only'), (b'closed', 'Only admin users who have permission to define and edit taxonomies'), (b'open', 'Any user who has permission to use taxonomies')]),
),
]
......@@ -31,6 +31,8 @@ class Taxonomy(models.Model):
def __unicode__(self):
return self.name
# To do Categories, you use 'optional' and 'closed',
# to do free tagging use 'multiple' and 'open'
multiplicity = models.CharField(
choices=(
('optional', _('Zero or One')),
......@@ -40,20 +42,19 @@ class Taxonomy(models.Model):
max_length=30,
)
# My thoughts on how this grows...
#
#
# vocabulary = models.CharField(
# ...
# choices=(
# ('fixed', _('Not modifiable by any user, system only')),
# ('closed', _('Only admin users who have permission to define and edit taxonomies')),
# ('open', _('Any user who has permission to use taxonomies')),
# )
# )
vocabulary = models.CharField(
choices=(
('fixed', _('Not modifiable by any user, system only')),
('closed', _('Only admin users who have permission to define and edit taxonomies')),
('open', _('Any user who has permission to use taxonomies')),
),
default='closed',
max_length=30,
)
# To do Categories, you use 'optional' and 'closed',
# to do free tagging use 'multiple' and 'open'
@property
def is_open(self):
return self.vocabulary == 'open'
class TermManager(models.Manager):
......
......@@ -50,3 +50,24 @@ def test_is_optional_false_for_multiplicity_multiple():
taxonomy = TaxonomyFactory(multiplicity='multiple')
assert not taxonomy.is_optional
@pytest.mark.django_db
def test_is_open_true_for_vocabulary_open():
taxonomy = TaxonomyFactory(vocabulary='open')
assert taxonomy.is_open
@pytest.mark.django_db
def test_is_open_false_for_vocabulary_fixed():
taxonomy = TaxonomyFactory(vocabulary='fixed')
assert not taxonomy.is_open
@pytest.mark.django_db
def test_is_open_false_for_vocabulary_closed():
taxonomy = TaxonomyFactory(vocabulary='closed')
assert not taxonomy.is_open
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