diff --git a/.travis.yml b/.travis.yml index 4dac53f..81da493 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ env: - DJANGO_VERSION='Django>=1.9,<1.10' - DJANGO_VERSION='Django>=1.10,<1.11' - DJANGO_VERSION='Django>=1.11,<2.0' + - DJANGO_VERSION='Django>=2.0,<2.1' - DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz' matrix: exclude: @@ -29,8 +30,12 @@ matrix: env: DJANGO_VERSION='Django>=1.10,<1.11' - python: "2.6" env: DJANGO_VERSION='Django>=1.11,<2.0' + - python: "2.6" + env: DJANGO_VERSION='Django>=2.0,<2.1' - python: "2.6" env: DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz' + - python: "2.7" + env: DJANGO_VERSION='Django>=2.0,<2.1' - python: "2.7" env: DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz' - python: "3.3" @@ -43,6 +48,8 @@ matrix: env: DJANGO_VERSION='Django>=1.10,<1.11' - python: "3.3" env: DJANGO_VERSION='Django>=1.11,<2.0' + - python: "3.3" + env: DJANGO_VERSION='Django>=2.0,<2.1' - python: "3.3" env: DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz' - python: "3.4" diff --git a/example/app/models.py b/example/app/models.py index eb2819d..9d466e0 100644 --- a/example/app/models.py +++ b/example/app/models.py @@ -15,7 +15,7 @@ # along with this software. If not, see . from django.db import models -from django.utils.translation import gettext as _ +from django.utils.translation import gettext_lazy as _ from multiselectfield import MultiSelectField diff --git a/multiselectfield/db/fields.py b/multiselectfield/db/fields.py index 57b053f..87622ae 100644 --- a/multiselectfield/db/fields.py +++ b/multiselectfield/db/fields.py @@ -55,8 +55,8 @@ def __init__(self, choices, *args, **kwargs): 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]) + lst = [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 lst]) class MultiSelectField(models.CharField): @@ -74,7 +74,7 @@ def __init__(self, *args, **kwargs): self.validators.append(MaxChoicesValidator(self.max_choices)) def _get_flatchoices(self): - l = super(MultiSelectField, self)._get_flatchoices() + lst = super(MultiSelectField, self)._get_flatchoices() class MSFFlatchoices(list): # Used to trick django.contrib.admin.utils.display_for_field into @@ -83,7 +83,7 @@ class MSFFlatchoices(list): def __bool__(self): return False __nonzero__ = __bool__ - return MSFFlatchoices(l) + return MSFFlatchoices(lst) flatchoices = property(_get_flatchoices) def get_choices_default(self): @@ -102,7 +102,10 @@ def get_choices_selected(self, arr_choices): return choices_selected def value_to_string(self, obj): - value = self._get_val_from_obj(obj) + try: + value = self.val_from_object(obj) + except AttributeError: + value = self._get_val_from_obj(obj) return self.get_prep_value(value) def validate(self, value, model_instance):