django-select-multiple-field
django-select-multiple-field copied to clipboard
Fix RemoveInDjango110Warnings
Fix for issue #12: stop using SubfieldBase
Looks like #16 is not complete. We need to define also a from_db_value method. Otherwise, after retrieving the model instance from database, SelectMultipleField
will contain string (for example 'A,B'
) and not list (['A', 'B']
).
There is also some back incompatible change: when subclassing from SubfieldBase
, to_python
method is called on every assignment to the field. Looks like since django 1.8 this is not a recommended way, see docs. Now it works a little bit different.
I decided to make a django version specific condition to not break support for older django versions. But user's of django >= 1.8 must be aware, there is a incompatible change in this patch.
Before this patch:
class MyModel(models.Model):
multi = SelectMultipleField(choices=SOME_CHOICES)
obj = MyModel()
obj.multi = 'A'
obj.save()
assert obj.multi == ['A'] # value converted to list right after assignment
# by `to_python` method
After this patch:
obj = MyModel()
obj.multi = 'A'
obj.save()
assert obj.multi == 'A' # `to_python` method is not called on assignment
obj = MyModel.objects.get(pk=obj.pk)
assert obj.multi == ['A'] # but on retrieving from database data is converted
# to list by `from_db_value` method
:+1: Since this PR deals with Django 1.10 deprecation, it might be worth it to take care of this line too. The choices parameter was removed from render_options().
I tested your fork along with that change on 1.10, and it worked just fine.
Thanks, @mchill , fixed that. Also added Django 1.10 env to tox tests.
👍 Great patch, @kelvinwong-ca !
- Bump, any news on when this will go in ? Ive just upgraded my Django and this is failing as expected ...
Bump @kelvinwong-ca please can you approve patch.
Bump @kelvinwong-ca please merge pull request
Bump- also need this solved fast with a new release to pip
This is still not in - kinda frustrating. Can you please make it happen @kelvinwong-ca ?
@Letme
As a temporal solution can suggest to include following link in your requirements.txt
:
https://github.com/st4lk/django-select-multiple-field/archive/v0.5.0a-draft.zip
Thanks @st4lk - this works perfectly.
Please merge @st4lk thanks for the temp workaround
Waiting for the fix. Please merge and create release tag and put in PIP. Thanks.
I think it's clear at this point that this project is abandoned. The last commit is from December 2015, and @kelvinwong-ca never replied to this pull request (or the original #16)
@kelvinwong-ca in fact had absolutely no activity on Github since April 2016. Hopefully they are ok.
In any case, does anybody want to take over this project and continue it, merging this pull request and maybe the other ones, and becoming the new upstream?
I won't. We have our fork for Ideascube (the only difference being that we included this pull request) which works for us, and we already have too much on our plate. We'll happily follow whoever takes over this project, though.
Googling I found more recent project with support Django 1.10 and additional fixes: https://github.com/blag/django-multiselectfield
It has fixes for list_display
and list_filter
also
@sshishov Did you try using this other project you mentioned? Is it a drop-in replacement?
Also, any reason you pointed to https://github.com/blag/django-multiselectfield rather than its upstream, https://github.com/goinnn/django-multiselectfield ?
I'm going to try and have a look at it soon, but if you already did and have some feedback it would be useful. 😉