我有以下代码来序列化查询集;
def render_to_response(self, context, **response_kwargs):
return HttpResponse(json.simplejson.dumps(list(self.get_queryset())),
mimetype="application/json")
Run Code Online (Sandbox Code Playgroud)
以下是我的 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',.........]}]
Run Code Online (Sandbox Code Playgroud)
我需要序列化.但它说不能序列化<Product: hederello ()>.因为列表由django对象和dicts组成.有任何想法吗 ?
我有以下queryset:
prices = Price.objects.filter(product=product).values_list('price', 'valid_from')
Run Code Online (Sandbox Code Playgroud)
我如何得到"json"的价格
{"aaData": [
["70.1700", "2007-01-01"], # price, valid_form
["72.6500", "2008-01-01"], # price, valid_form
["74.5500", "2009-01-01"], # price, valid_form
["76.6500", "2010-01-01"]
]}
Run Code Online (Sandbox Code Playgroud)