从mongodb集合创建Model类或在django中创建JSON

时间:2014-03-12 03:22:07

标签: python json django mongodb

有没有办法使用已加载到mongodb中的数据或从新的django应用程序的JSON对象创建模型?我知道它可以手动完成,但考虑到JSON有很多键的事实,它将会很乏味。

编辑:

我正在使用Yelp数据集。数据采用JSON格式,目前存储在MongoDB中。

示例:

{
   "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"
}

到目前为止,我一直在使用pymongo查询数据,但我想使用django模型。我正在寻找的是从现有数据生成模型的便捷方式。

0 个答案:

没有答案