django-select-multiple-field icon indicating copy to clipboard operation
django-select-multiple-field copied to clipboard

Fix RemoveInDjango110Warnings

Open st4lk opened this issue 8 years ago • 17 comments

Fix for issue #12: stop using SubfieldBase

st4lk avatar Aug 12 '16 22:08 st4lk

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']).

st4lk avatar Aug 12 '16 22:08 st4lk

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

st4lk avatar Aug 13 '16 10:08 st4lk

:+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.

mchill avatar Sep 08 '16 01:09 mchill

Thanks, @mchill , fixed that. Also added Django 1.10 env to tox tests.

st4lk avatar Sep 08 '16 10:09 st4lk

👍 Great patch, @kelvinwong-ca !

matiasherranz avatar Sep 09 '16 14:09 matiasherranz

  • Bump, any news on when this will go in ? Ive just upgraded my Django and this is failing as expected ...

farridav avatar Oct 17 '16 09:10 farridav

Bump @kelvinwong-ca please can you approve patch.

manevant avatar Nov 09 '16 14:11 manevant

Bump @kelvinwong-ca please merge pull request

poskadesign avatar Nov 17 '16 08:11 poskadesign

Bump- also need this solved fast with a new release to pip

Letme avatar Nov 24 '16 06:11 Letme

This is still not in - kinda frustrating. Can you please make it happen @kelvinwong-ca ?

Letme avatar Jan 07 '17 19:01 Letme

@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

st4lk avatar Jan 07 '17 21:01 st4lk

Thanks @st4lk - this works perfectly.

Letme avatar Jan 09 '17 09:01 Letme

Please merge @st4lk thanks for the temp workaround

acidjunk avatar Jan 16 '17 10:01 acidjunk

Waiting for the fix. Please merge and create release tag and put in PIP. Thanks.

sshishov avatar Mar 23 '17 09:03 sshishov

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.

bochecha avatar Mar 23 '17 10:03 bochecha

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 avatar Mar 23 '17 10:03 sshishov

@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. 😉

bochecha avatar Apr 28 '17 08:04 bochecha