diff --git a/CHANGES.rst b/CHANGES.rst index 74eb663..fc6a0e1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,9 @@ CHANGES master (unreleased) ------------------- +* Fixed bug with checking for field name conflicts for added query managers on + `StatusModel`. + * Can pass `choices_name` to `StatusField` to use a different name for choices class attribute. ``STATUS`` is used by default. diff --git a/model_utils/models.py b/model_utils/models.py index 0ad9d32..8030bea 100644 --- a/model_utils/models.py +++ b/model_utils/models.py @@ -58,13 +58,13 @@ def add_status_query_managers(sender, **kwargs): """ if not issubclass(sender, StatusModel): return - for value, name in getattr(sender, 'STATUS', ()): + for value, display in getattr(sender, 'STATUS', ()): try: - sender._meta.get_field(name) + sender._meta.get_field(value) raise ImproperlyConfigured("StatusModel: Model '%s' has a field " "named '%s' which conflicts with a " "status of the same name." - % (sender.__name__, name)) + % (sender.__name__, value)) except FieldDoesNotExist: pass sender.add_to_class(value, QueryManager(status=value)) diff --git a/model_utils/tests/tests.py b/model_utils/tests/tests.py index 4553ed4..070ba46 100644 --- a/model_utils/tests/tests.py +++ b/model_utils/tests/tests.py @@ -1132,8 +1132,8 @@ class StatusManagerAddedTests(TestCase): with self.assertRaises(ImproperlyConfigured): class ErrorModel(StatusModel): STATUS = ( - ('active', 'active'), - ('deleted', 'deleted'), + ('active', 'Is Active'), + ('deleted', 'Is Deleted'), ) active = models.BooleanField() diff --git a/runtests.py b/runtests.py index 5f99366..1bb3526 100755 --- a/runtests.py +++ b/runtests.py @@ -3,26 +3,31 @@ import os, sys from django.conf import settings +import django -if not settings.configured: - settings_dict = dict( - INSTALLED_APPS=( - 'django.contrib.contenttypes', - 'model_utils', - 'model_utils.tests', - ), - DATABASES={ - "default": { - "ENGINE": "django.db.backends.sqlite3" - } - }, - ) - - settings.configure(**settings_dict) +DEFAULT_SETTINGS = dict( + INSTALLED_APPS=( + 'django.contrib.contenttypes', + 'model_utils', + 'model_utils.tests', + ), + DATABASES={ + "default": { + "ENGINE": "django.db.backends.sqlite3" + } + }, + ) def runtests(*test_args): + if not settings.configured: + settings.configure(**DEFAULT_SETTINGS) + + # Compatibility with Django 1.7's stricter initialization + if hasattr(django, 'setup'): + django.setup() + if not test_args: test_args = ['tests'] diff --git a/tox.ini b/tox.ini index 6067c98..b754bc7 100644 --- a/tox.ini +++ b/tox.ini @@ -14,14 +14,14 @@ commands = coverage run -a setup.py test [testenv:py26-1.4] basepython = python2.6 deps = - Django == 1.4.5 + Django == 1.4.10 South == 0.7.6 coverage == 3.6 [testenv:py26-1.5] basepython = python2.6 deps = - Django == 1.5.1 + Django == 1.5.5 South == 0.8.1 coverage == 3.6 @@ -35,21 +35,21 @@ deps = [testenv:py27-1.4] basepython = python2.7 deps = - Django == 1.4.5 + Django == 1.4.10 South == 0.8.1 coverage == 3.6 [testenv:py27-1.5] basepython = python2.7 deps = - Django == 1.5.1 + Django == 1.5.5 South == 0.8.1 coverage == 3.6 [testenv:py27-1.6] basepython = python2.7 deps = - https://github.com/django/django/tarball/stable/1.6.x + Django == 1.6.1 South == 0.8.1 coverage == 3.6 @@ -63,20 +63,20 @@ deps = [testenv:py27-1.5-nosouth] basepython = python2.7 deps = - Django == 1.5.1 + Django == 1.5.5 coverage == 3.6 [testenv:py32-1.5] basepython = python3.2 deps = - Django == 1.5.1 + Django == 1.5.5 South == 0.8.1 coverage == 3.6 [testenv:py32-1.6] basepython = python3.2 deps = - https://github.com/django/django/tarball/stable/1.6.x + Django == 1.6.1 South == 0.8.1 coverage == 3.6 @@ -90,14 +90,14 @@ deps = [testenv:py33-1.5] basepython = python3.3 deps = - Django == 1.5.1 + Django == 1.5.5 South == 0.8.1 coverage == 3.6 [testenv:py33-1.6] basepython = python3.3 deps = - https://github.com/django/django/tarball/stable/1.6.x + Django == 1.6.1 South == 0.8.1 coverage == 3.6