- June 3, 2011
- 1 (after 1 ratings)
Perhaps this is blindingly obvious but I spent a while trying to get this, before figuring out that when a each item of an iterated ValuesQuerySet is a dict.
Useful for serialising to JSON or XML etc.
1 2 3 4 5 6 7
def ValuesQuerySetToDict(vqs): return [item for item in vqs] # Usage data=MyModel.objects.values('id','title','...','...') data_dict = ValuesQuerySetToDict(data) data_json = simplejson.dumps(data_dict)
More like this
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 4 weeks ago
- Python Django CRUD Example Tutorial by tuts_station 1 month, 2 weeks ago
- Browser-native date input field by kytta 2 months, 4 weeks ago
- Generate and render HTML Table by LLyaudet 3 months, 1 week ago
- My firs Snippets by GutemaG 3 months, 1 week ago