django-multiselectfield
django-multiselectfield copied to clipboard
CommandError: Unable to serialize database: 'MultiSelectField' object has no attribute '_get_val_from_obj'
When trying to dumpdata with a model that uses multiselectfield in Django 2.0 I get this … is this me doing something wrong or something to do with multiselectfield? Thanks for any insight and for multiselectfield!
This project doesn't support Django 2.0+ yet. I'll happily accept PRs for it though.
This project is also a dirty hack - if you will ever do any filtering on the MultiSelectField you will want to use Django's full many to many relation instead.
I'll leave this issue open until the project is compatible with Django 2.0. Thanks!
What would be the first steps to making this compatible with Django 2.0? I'm happy to do some research and help where I can. The error I am getting starts with CommandError: Unable to serialize database: 'MultiSelectField' object has no attribute '_get_val_from_obj' yet when I google "Django 2.0 _get_val_from_obj", it looks like it's been deprecated in Django 2.0.
@CodyBontecou to make it work with Django 2.0 you can simply change one line in multiselectfield/db/fields.py
Change line 105 from value = self._get_val_from_obj(obj) to value = self.value_from_object(obj)
Then it should work just fine (at least dumpdata works for me again)
I've started a branch and PR for Django 2.0 compatibility: #77. It's currently running into issues and I don't have time to debug all of it right now. Help wanted.
@brathis, Thanks, it also makes jsonify work
Is this bug still live?
I use master branch version (0.1.8) on Django 2.0.5, but have CommandError: Unable to serialize database: 'MultiSelectField' object has no attribute '_get_val_from_obj' after use ./manage.py dumpdata ... command.
Way to solve it?
If you just want to fix this particular issue in Django >2.0 before the PR is merged and still want a clean env, create a new class:
from multiselectfield import MultiSelectField
class PatchedMultiSelectField(MultiSelectField):
def value_to_string(self, obj):
value = self.value_from_object(obj)
return self.get_prep_value(value)
and use that in your model.
I think this can be closed as the changes of #99 are already released with v0.1.10?