summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2018-06-18 14:01:19 +0200
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2018-06-18 14:01:19 +0200
commite677698e8330bc3374054a6669df694a85ea54e6 (patch)
treea965f99c92b481fbf7cb3873b1628f2e9779bf6b
parent76be56977c8c81e00966b1c49f82ecbb0361b904 (diff)
downloadsemantic-version-e677698e8330bc3374054a6669df694a85ea54e6.tar.gz
Adapt code to Django>=1.11.
Drop compatibility layer for Django<1.11.
-rw-r--r--semantic_version/django_fields.py10
-rw-r--r--tests/test_django.py9
2 files changed, 2 insertions, 17 deletions
diff --git a/semantic_version/django_fields.py b/semantic_version/django_fields.py
index 478cf7b..39a6c4b 100644
--- a/semantic_version/django_fields.py
+++ b/semantic_version/django_fields.py
@@ -4,7 +4,6 @@
from __future__ import unicode_literals
-import django
from django.db import models
from django.utils.translation import ugettext_lazy as _
@@ -17,13 +16,6 @@ class SemVerField(models.CharField):
kwargs.setdefault('max_length', 200)
super(SemVerField, self).__init__(*args, **kwargs)
- if django.VERSION[:2] < (1, 8):
- def contribute_to_class(self, cls, name, **kwargs):
- """Emulate SubFieldBase for Django < 1.8"""
- super(SemVerField, self).contribute_to_class(cls, name, **kwargs)
- from django.db.models.fields import subclassing
- setattr(cls, self.name, subclassing.Creator(self))
-
def from_db_value(self, value, expression, connection, context):
"""Convert from the database format.
@@ -40,7 +32,7 @@ class SemVerField(models.CharField):
return value
def value_to_string(self, obj):
- value = self.to_python(self._get_val_from_obj(obj))
+ value = self.to_python(self.value_from_object(obj))
return str(value)
def run_validators(self, value):
diff --git a/tests/test_django.py b/tests/test_django.py
index 1c3c46a..273633c 100644
--- a/tests/test_django.py
+++ b/tests/test_django.py
@@ -139,7 +139,6 @@ class DjangoFieldTestCase(unittest.TestCase):
self.assertEqual(Version('23.0.0'), obj2.version)
self.assertEqual(Version('0.1.2+3.4.5-6', partial=True), obj2.partial)
- @unittest.skipIf(django.VERSION[:2] < (1, 8), "Django<1.8 casts values on setattr")
def test_invalid_input(self):
v = models.VersionModel(version='0.1.1', spec='blah')
self.assertRaises(ValueError, v.full_clean)
@@ -147,11 +146,6 @@ class DjangoFieldTestCase(unittest.TestCase):
v2 = models.VersionModel(version='0.1', spec='==0.1.1,!=0.1.1-alpha')
self.assertRaises(ValueError, v2.full_clean)
- @unittest.skipUnless(django.VERSION[:2] < (1, 8), "Django>=1.8 doesn't mangle setattr")
- def test_invalid_input_full_clean(self):
- self.assertRaises(ValueError, models.VersionModel, version='0.1.1', spec='blah')
- self.assertRaises(ValueError, models.VersionModel, version='0.1', spec='==0.1.1,!=0.1.1-alpha')
-
def test_partial(self):
obj = models.PartialVersionModel(partial=Version('0.1.0'))
@@ -244,8 +238,7 @@ class FullMigrateTests(TransactionTestCase):
call_command('migrate', verbosity=0)
with connection.cursor() as cursor:
table_list = connection.introspection.get_table_list(cursor)
- if django.VERSION[:2] >= (1, 8):
- table_list = [t.name for t in connection.introspection.get_table_list(cursor)]
+ table_list = [t.name for t in connection.introspection.get_table_list(cursor)]
self.assertIn('django_test_app_versionmodel', table_list)