def create(self):
     try:
        categories = Category.all()
        for category in categories:
          name = self.params.get("name_%s" % category.category_id)
          id = self.params.get("category_%s" % category.category_id)
          wk = db.GqlQuery("SELECT * FROM Category WHERE category_id = :1",id).get()
          if wk != None:
            category.name=name
            category.category_id = id
            category.put()

        new = self.params['new_category']
        if new:
          id = self.params['new_category_id']
          category = Category(name=new, category_id=id,order=max)
          category.put()

        # URL '/category/' にリダイレクト
        self.redirect('/site/category/')
     except Exception, ex:
        # 例外メッセージを表示する
        self.render(text='Exception: %s' % ex)
Beispiel #2
0
def add(restaurant, category_name): 
  if isinstance(restaurant, str) or isinstance(restaurant, unicode):
    restaurant = ndb.Key(Restaurant, restaurant)
  check_get_restaurant(restaurant)
  category = Category(restaurant_key = restaurant, name = category_name)
  return category.put().get()
Beispiel #3
0
 def testInsertEntity(self):
   category = Category()
   category.put()
   self.assertEqual(1, len(Category.query().fetch(2)))