diff --git a/example/app/test_msf.py b/example/app/test_msf.py
index b5e3932..dc057ee 100644
--- a/example/app/test_msf.py
+++ b/example/app/test_msf.py
@@ -32,12 +32,8 @@ else:
u = str
-if VERSION < (1, 9):
- def get_field(model, name):
- return model._meta.get_field_by_name(name)[0]
-else:
- def get_field(model, name):
- return model._meta.get_field(name)
+def get_field(model, name):
+ return model._meta.get_field(name)
class MultiSelectTestCase(TestCase):
@@ -77,12 +73,8 @@ class MultiSelectTestCase(TestCase):
# call Field.from_db_field, it simply returns a Python representation
# of the data in the database (which in our case is a string of
# comma-separated values). The bug was fixed in Django 1.8+.
- if VERSION >= (1, 6) and VERSION < (1, 8):
- self.assertStringEqual(tag_list_list, [u('sex,work,happy')])
- self.assertStringEqual(categories_list_list, [u('1,3,5')])
- else:
- self.assertListEqual(tag_list_list, [['sex', 'work', 'happy']])
- self.assertListEqual(categories_list_list, [['1', '3', '5']])
+ self.assertListEqual(tag_list_list, [['sex', 'work', 'happy']])
+ self.assertListEqual(categories_list_list, [['1', '3', '5']])
def test_form(self):
form_class = modelform_factory(Book, fields=('title', 'tags', 'categories'))
@@ -139,7 +131,7 @@ class MultiSelectTestCase(TestCase):
self.assertEqual(len(form_class.base_fields), 1)
form = form_class(initial={'published_in': ['BC', 'AK']})
- expected_html = u("""
- Canada - Provinces
\n"""
+ expected_html = u("""
- Canada - Provinces
\n"""
"""- USA - States
\n"""
"""\n"""
@@ -147,18 +139,10 @@ class MultiSelectTestCase(TestCase):
actual_html = form.as_p()
- if (1, 11) <= VERSION < (2, 0):
- # Django 1.11+ does not assign 'for' attributes on labels if they
- # are group labels
- expected_html = expected_html.replace('label for="id_published_in_0"', 'label')
+ if VERSION >= (2, 0):
+ expected_html = expected_html.replace('input checked="checked"', 'input checked')
- if VERSION < (1, 6):
- # Django 1.6 renders the Python repr() for each group (eg: tuples
- # with HTML entities), so we skip the test for that version
- self.assertEqual(expected_html.replace('\n', ''), actual_html.replace('\n', ''))
-
- if VERSION >= (1, 7):
- self.assertHTMLEqual(expected_html, actual_html)
+ self.assertHTMLEqual(expected_html, actual_html)
class MultiSelectUtilsTestCase(TestCase):
diff --git a/example/app/views.py b/example/app/views.py
index 3b0bc22..6142ef1 100644
--- a/example/app/views.py
+++ b/example/app/views.py
@@ -19,7 +19,7 @@ from django.conf import settings
from django.contrib.auth import login
from django.contrib.auth import get_user_model
-from django.core.urlresolvers import reverse
+from django.urls import reverse
from django.http import HttpResponseRedirect
diff --git a/example/example/urls.py b/example/example/urls.py
index efa4a7b..0e60278 100644
--- a/example/example/urls.py
+++ b/example/example/urls.py
@@ -14,43 +14,33 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this software. If not, see .
-from django import VERSION
from django.conf import settings
try:
from django.conf.urls import include, url
-
- # Compatibility for Django > 1.8
- def patterns(prefix, *args):
- if VERSION < (1, 9):
- from django.conf.urls import patterns as django_patterns
- return django_patterns(prefix, *args)
- elif prefix != '':
- raise NotImplementedError("You need to update your URLConf for "
- "Django 1.10, or tweak it to remove the "
- "prefix parameter")
- else:
- return list(args)
-except ImportError: # Django < 1.4
- from django.conf.urls.defaults import include, patterns, url
-
+except ImportError:
+ from django.urls import include, url
from django.contrib import admin
from django.views.static import serve
+
admin.autodiscover()
js_info_dict = {
'packages': ('django.conf',),
}
-urlpatterns = patterns(
- '',
+urlpatterns = [
url(r'^', include('app.urls')),
- url(r'^admin/', include(admin.site.urls)),
-)
+ url(r'^admin/', admin.site.urls),
+]
-urlpatterns += patterns(
- '',
- url(r'^%s(?P.*)$' % settings.MEDIA_URL[1:],
+urlpatterns += [
+ url(
+ r'^%s(?P.*)$' % settings.MEDIA_URL[1:],
serve,
- {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
-)
+ {
+ 'document_root': settings.MEDIA_ROOT,
+ 'show_indexes': True,
+ },
+ ),
+]
diff --git a/example/run_tests.py b/example/run_tests.py
index 9cc12c4..ec3f39a 100644
--- a/example/run_tests.py
+++ b/example/run_tests.py
@@ -19,10 +19,9 @@
import os
import sys
-import django
-
from django.conf import ENVIRONMENT_VARIABLE
from django.core import management
+from django.core.wsgi import get_wsgi_application
if len(sys.argv) == 1:
@@ -30,8 +29,6 @@ if len(sys.argv) == 1:
else:
os.environ[ENVIRONMENT_VARIABLE] = sys.argv[1]
-if django.VERSION[0] == 1 and django.VERSION[1] >= 7:
- from django.core.wsgi import get_wsgi_application
- application = get_wsgi_application()
+application = get_wsgi_application()
management.call_command('test', 'app')
diff --git a/multiselectfield/db/fields.py b/multiselectfield/db/fields.py
index 57b053f..e10832d 100644
--- a/multiselectfield/db/fields.py
+++ b/multiselectfield/db/fields.py
@@ -55,8 +55,8 @@ class MSFList(list):
super(MSFList, self).__init__(*args, **kwargs)
def __str__(msgl):
- l = [msgl.choices.get(int(i)) if i.isdigit() else msgl.choices.get(i) for i in msgl]
- return u', '.join([string_type(s) for s in l])
+ list = [msgl.choices.get(int(i)) if i.isdigit() else msgl.choices.get(i) for i in msgl]
+ return u', '.join([string_type(s) for s in list])
class MultiSelectField(models.CharField):
@@ -74,7 +74,7 @@ class MultiSelectField(models.CharField):
self.validators.append(MaxChoicesValidator(self.max_choices))
def _get_flatchoices(self):
- l = super(MultiSelectField, self)._get_flatchoices()
+ choices = super(MultiSelectField, self)._get_flatchoices()
class MSFFlatchoices(list):
# Used to trick django.contrib.admin.utils.display_for_field into
@@ -83,7 +83,7 @@ class MultiSelectField(models.CharField):
def __bool__(self):
return False
__nonzero__ = __bool__
- return MSFFlatchoices(l)
+ return MSFFlatchoices(choices)
flatchoices = property(_get_flatchoices)
def get_choices_default(self):
@@ -102,7 +102,7 @@ class MultiSelectField(models.CharField):
return choices_selected
def value_to_string(self, obj):
- value = self._get_val_from_obj(obj)
+ value = super(MultiSelectField, self).value_from_object(obj)
return self.get_prep_value(value)
def validate(self, value, model_instance):