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

Re-adding check for None to clean() (#80) #83

Merged
merged 3 commits into from
Jun 28, 2016
Merged
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
2 changes: 1 addition & 1 deletion sortedm2m/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-


__version__ = '1.3.0.dev1'
__version__ = '1.3.1'
5 changes: 3 additions & 2 deletions sortedm2m/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from itertools import chain
from django import forms
from django.conf import settings
from django.db.models.query import QuerySet
from django.template.loader import render_to_string
from django.utils.encoding import force_text
from django.utils.html import conditional_escape, escape
Expand Down Expand Up @@ -105,7 +104,9 @@ class SortedMultipleChoiceField(forms.ModelMultipleChoiceField):
widget = SortedCheckboxSelectMultiple

def clean(self, value):
queryset = super(SortedMultipleChoiceField, self).clean(value)
queryset = super(SortedMultipleChoiceField, self).clean(value)
if value is None or not hasattr(queryset, '__iter__'):
return queryset
key = self.to_field_name or 'pk'
objects = dict((force_text(getattr(o, key)), o) for o in queryset)
return [objects[force_text(val)] for val in value]
Expand Down