django-multiselectfield icon indicating copy to clipboard operation
django-multiselectfield copied to clipboard

CommandError: Unable to serialize database: 'MultiSelectField' object has no attribute '_get_val_from_obj'

Open aclark4life opened this issue 7 years ago • 8 comments

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!

aclark4life avatar Dec 28 '17 16:12 aclark4life

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!

blag avatar Dec 28 '17 20:12 blag

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 avatar Jan 26 '18 04:01 CodyBontecou

@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)

brathis avatar Jan 28 '18 11:01 brathis

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.

blag avatar Jan 29 '18 05:01 blag

@brathis, Thanks, it also makes jsonify work

scientifichackers avatar Mar 06 '18 16:03 scientifichackers

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?

koddr avatar May 22 '18 19:05 koddr

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.

bjornuppeke avatar Sep 24 '18 09:09 bjornuppeke

I think this can be closed as the changes of #99 are already released with v0.1.10?

wfehr avatar Nov 06 '19 06:11 wfehr