Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Django 2.0 #77

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion example/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this software. If not, see <http://www.gnu.org/licenses/>.

from django.db import models
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy as _

from multiselectfield import MultiSelectField

Expand Down
13 changes: 8 additions & 5 deletions multiselectfield/db/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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):
Expand Down