python+django 尝试将 mongoengine 文档序列化为 json 但仅获取字段名称数组

python+django trying to serialize mongoengine documents to json but getting only arrays of fields names

我有以下型号:

class Estados(Document):
    Nome = StringField(max_length = 20, required=True)
    Sigla = StringField(max_length = 2, required=True)
    Cidades = ListField(StringField)

当我查询它时,用这个方法:

from django.http import HttpRequest
from app.models import Estados
from django.http import HttpResponse
from bson.json_util import dumps, default
import sys
import mongoengine

def BuscarEstados(request):
    erro = None
    dados = []
    try:
        dados = Estados.objects.exclude('Cidades').all()
    except Exception as e:
        erro = 'Solicicação inválida: ' + str(e)

    return HttpResponse(dumps({ 'erro': erro, 'dados': dados}, default=default))

我只得到具有以下字段名称的数组:

{"dados": [["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"], ["id", "Nome", "Sigla", "Cidades"]], "erro": null}

请问我做错了什么?

我正在使用 Django 1.10.4、pymongo 3.4.0、mongoengine 0.11.0 和 python 3.5

我找到了解决方案...不幸的是,MongoEngine 的文档仍在增长...

他们为文档提供了一个方法 to_json()。

所以:

dados = Estados.objects.exclude('Cidades').all().to_json()