AttributeError with Django REST Framework and MongoEngine

一个人想着一个人 提交于 2019-12-05 15:12:58
evermean

Finally got the solution. I needed to explicitly set many=False to make it work. So this works fine:

from core.models import * 
from core.serializers import *
tiger = Lady(firstname='Tiger', lastname="Lily")
serial = LadySerializer(tiger, many=False)
serial.data

and yields:

{'firstname': u'Tiger', 'lastname': u'Lily'}

You can find some additional information regarding this problem here. The interesting part for this case is the following post:

Version 2.2 starts the deprecation of the implicit iteration behavior. At the moment you'll need to explicitly specify many=False to force the behavior to not iterate over __iter__ style objects. By 2.4 the default value will switch from None to False.

Hope this helps....

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!