dimanche 25 mai 2014

python - classes de création de modèle de la collection mongodb ou JSON dans django - Stack Overflow


Is there a way to create model using data that has already been loaded into mongodb or from a JSON object for a new django application? I know that it can be done manually, but considering the fact the JSON has many keys, it is going to be tedious.


EDIT:


I am using the Yelp dataset. The data is in the form of JSON, which is currently stored in MongoDB.


Example:


{
"business_id":"O_X3PGhk3Y5JWVi866qlJg",
"full_address":"1501 W Bell Rd\nPhoenix, AZ 85023",
"hours":{
"Monday":{
"close":"18:00",
"open":"11:00"
},
"Tuesday":{
"close":"18:00",
"open":"11:00"
},
"Friday":{
"close":"18:00",
"open":"11:00"
},
"Wednesday":{
"close":"18:00",
"open":"11:00"
},
"Thursday":{
"close":"18:00",
"open":"11:00"
},
"Sunday":{
"close":"18:00",
"open":"11:00"
},
"Saturday":{
"close":"18:00",
"open":"11:00"
}
},
"open":true,
"categories":[
"Active Life",
"Arts & Entertainment",
"Stadiums & Arenas",
"Horse Racing"
],
"city":"Phoenix",
"review_count":29,
"name":"Turf Paradise Race Course",
"neighborhoods":[

],
"longitude":-112.0923293,
"state":"AZ",
"stars":4.0,
"latitude":33.638572699999997,
"attributes":{
"Take-out":false,
"Wi-Fi":"free",
"Good For":{
"dessert":false,
"latenight":false,
"lunch":false,
"dinner":false,
"brunch":false,
"breakfast":false
},
"Noise Level":"average",
"Takes Reservations":true,
"Has TV":true,
"Delivery":false,
"Ambience":{
"romantic":false,
"intimate":false,
"touristy":false,
"hipster":false,
"divey":false,
"classy":false,
"trendy":false,
"upscale":false,
"casual":false
},
"Parking":{
"garage":false,
"street":false,
"validated":false,
"lot":true,
"valet":true
},
"Wheelchair Accessible":true,
"Outdoor Seating":true,
"Attire":"casual",
"Alcohol":"full_bar",
"Waiter Service":true,
"Accepts Credit Cards":true,
"Good for Kids":false,
"Good For Groups":true,
"Price Range":2
},
"type":"business"
}

SO far, I've been querying the data using pymongo, but I would like to use django models. What I'm looking for is a convenient way to generate a model from the already existing data.



Is there a way to create model using data that has already been loaded into mongodb or from a JSON object for a new django application? I know that it can be done manually, but considering the fact the JSON has many keys, it is going to be tedious.


EDIT:


I am using the Yelp dataset. The data is in the form of JSON, which is currently stored in MongoDB.


Example:


{
"business_id":"O_X3PGhk3Y5JWVi866qlJg",
"full_address":"1501 W Bell Rd\nPhoenix, AZ 85023",
"hours":{
"Monday":{
"close":"18:00",
"open":"11:00"
},
"Tuesday":{
"close":"18:00",
"open":"11:00"
},
"Friday":{
"close":"18:00",
"open":"11:00"
},
"Wednesday":{
"close":"18:00",
"open":"11:00"
},
"Thursday":{
"close":"18:00",
"open":"11:00"
},
"Sunday":{
"close":"18:00",
"open":"11:00"
},
"Saturday":{
"close":"18:00",
"open":"11:00"
}
},
"open":true,
"categories":[
"Active Life",
"Arts & Entertainment",
"Stadiums & Arenas",
"Horse Racing"
],
"city":"Phoenix",
"review_count":29,
"name":"Turf Paradise Race Course",
"neighborhoods":[

],
"longitude":-112.0923293,
"state":"AZ",
"stars":4.0,
"latitude":33.638572699999997,
"attributes":{
"Take-out":false,
"Wi-Fi":"free",
"Good For":{
"dessert":false,
"latenight":false,
"lunch":false,
"dinner":false,
"brunch":false,
"breakfast":false
},
"Noise Level":"average",
"Takes Reservations":true,
"Has TV":true,
"Delivery":false,
"Ambience":{
"romantic":false,
"intimate":false,
"touristy":false,
"hipster":false,
"divey":false,
"classy":false,
"trendy":false,
"upscale":false,
"casual":false
},
"Parking":{
"garage":false,
"street":false,
"validated":false,
"lot":true,
"valet":true
},
"Wheelchair Accessible":true,
"Outdoor Seating":true,
"Attire":"casual",
"Alcohol":"full_bar",
"Waiter Service":true,
"Accepts Credit Cards":true,
"Good for Kids":false,
"Good For Groups":true,
"Price Range":2
},
"type":"business"
}

SO far, I've been querying the data using pymongo, but I would like to use django models. What I'm looking for is a convenient way to generate a model from the already existing data.


0 commentaires:

Enregistrer un commentaire