【发布时间】:2013-05-23 07:48:40
【问题描述】:
我有以下代码用于序列化查询集;
def render_to_response(self, context, **response_kwargs):
return HttpResponse(json.simplejson.dumps(list(self.get_queryset())),
mimetype="application/json")
以下是我的get_querset()
[{'product': <Product: hederello ()>, u'_id': u'9802', u'_source': {u'code': u'23981', u'facilities': [{u'facility': {u'name': {u'fr': u'G\xe9n\xe9ral', u'en': u'General'}, u'value': {u'fr': [u'bar', u'r\xe9ception ouverte 24h/24', u'chambres non-fumeurs', u'chambres familiales',.........]}]
我需要序列化。但它说无法序列化<Product: hederello ()>。因为列表由 django 对象和 dicts 组成。有任何想法吗 ?
【问题讨论】:
标签: python django json serialization django-class-based-views