Convert data retrieved from MySQL database into JSON object using Python/Django

Posted by rohanbk on Stack Overflow See other posts from Stack Overflow or by rohanbk
Published on 2010-05-30T19:27:39Z Indexed on 2010/05/30 19:32 UTC
Read the original article Hit count: 315

Filed under:
|
|

I have a MySQL database called People which contains the following schema <id,name,foodchoice1,foodchoice2>. The database contains a list of people and the two choices of food they wish to have at a party (for example). I want to create some kind of Python web-service that will output a JSON object.

An example of output should be like:

{
"guestlist": [
{"id":1,"name":"Bob","choice1":"chicken","choice2":"pasta"},{"id":2,"name":"Alice","choice1":"pasta","choice2":"chicken"}
], 
"partyname": "My awesome party", "day": "1", "month": "June", "2010": "null"
}

Basically every guest is stored into a dictionary 'guestlist' along with their choices of food. At the end of the JSON object is just some additional information that only needs to be mentioned once.

The question that I have is regarding the method that I need to utilize to grab the data from my database, and create the JSON object. Do I need to use a standard Model/View structure of Django or can I get away with something that is much simpler since what I need to do is really simple?

© Stack Overflow or respective owner

Related posts about python

Related posts about django