I have a Django model with a JSONField to handle multilingual text as follows:
from django.contrib.postgres.fields import JSONField
def default_language_JSON():
content = {}
for lang in settings.LANGUAGES:
content[lang[0]] = ''
return content
class Entity(PolymorphicModel, ShowFieldType):
displayedNames = JSONField(
null = True,
blank = True,
verbose_name=_('Displayed names'),
help_text= _('These names are usually created automatically'),
default = default_language_JSON
)
...
When I try to dump the data with:
python3 manage.py dumpdata --natural-foreign --indent 4 --format=xml --verbosity 1 -o Database.xml
I get the error:
CommandError: Unable to serialize database: expected string or bytes-like object
I suppose it may have to do with the way the JSONField is serialized and I suspect the answer might be the encoder that should be used (as described in the documentation)
If I try dumping data in JSON or YAML no such error appears.
I use Django 2.1.4 in Ubuntu 16.04 with PostgreSQL 9.5
Any ideas?