Skip to content

Commit

Permalink
Fix slug field handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lpomfrey committed Nov 6, 2013
1 parent 617057f commit f74de53
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
19 changes: 19 additions & 0 deletions taggit_machinetags/fields.py
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import re

from django.core.validators import RegexValidator
from django.db.models.fields import SlugField


slug_re = re.compile(r'^[-a-zA-Z0-9_]+(:[-a-zA-Z0-9_]+)?$')
validate_slug = RegexValidator(
slug_re,
'Enter a valid slug with an optional colon separator.'
)


class MachineSlugField(SlugField):

default_validators = [validate_slug]
4 changes: 3 additions & 1 deletion taggit_machinetags/models.py
Expand Up @@ -6,6 +6,8 @@
from django.template.defaultfilters import slugify
from taggit.models import GenericTaggedItemBase

from taggit_machinetags.fields import MachineSlugField


@python_2_unicode_compatible
class MachineTagBase(models.Model):
Expand All @@ -15,7 +17,7 @@ class MachineTagBase(models.Model):
namespace = models.CharField(max_length=100, blank=True, default='')
namespace_slug = models.SlugField(
max_length=100, blank=True, default='', editable=False)
slug = models.SlugField(
slug = MachineSlugField(
max_length=201, unique=True, db_index=True, editable=False)

class Meta:
Expand Down
5 changes: 3 additions & 2 deletions taggit_machinetags/tests.py
Expand Up @@ -5,8 +5,9 @@
from django_any import any_model
from mock import Mock

from .managers import _MachineTaggableManager, MachineTaggableManager
from .models import MachineTag
from taggit_machinetags.managers import (
_MachineTaggableManager, MachineTaggableManager)
from taggit_machinetags.models import MachineTag


class TestMachineTagModel(TransactionTestCase):
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -4,5 +4,6 @@ envlist = py27, py33, pypy
[testenv]
PYTHONPATH = {toxinidir}:{toxinidir}/debreach
commands = python setup.py test
install_command = pip install {opts} {packages}
deps =
-r{toxinidir}/requirements.txt

0 comments on commit f74de53

Please sign in to comment.