- 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 3 months ago
- Python Django CRUD Example Tutorial by tuts_station 3 months, 2 weeks ago
- Browser-native date input field by kytta 5 months ago
- Generate and render HTML Table by LLyaudet 5 months, 1 week ago
- My firs Snippets by GutemaG 5 months, 1 week ago