多对多关系+ Google Datastore + Python

时间:2011-08-30 14:53:44

标签: google-app-engine google-cloud-datastore

鉴于以下日志:

Restaurant = <persistence.model.Restaurant object at 0x3913c01e89e78a20>
Review Content = This is my first comment...
User[0] = <persistence.model.User object at 0x3913c01e89e780a0>

以下代码:

class RestaurantReview(db.Model):
    owned_by = db.ReferenceProperty(Restaurant, required=True, collection_name='restaurant')
    written_by = db.ReferenceProperty(User, required=True, collection_name='user')
    content = db.StringProperty(required=True)
    date = db.DateTimeProperty(auto_now_add=True)

当我尝试创建RestaurantReview的实例时,它永远不会起作用:

RestaurantReview(owned_by=restaurant, written_by=user[0], content=restaurant_review_content.__str__()).put()    

EDIT 知道发生了什么事吗?它不断抛出我设置的自定义错误。

try:

        RestaurantReview(owned_by=restaurant, written_by=user[0], content=restaurant_review_content.__str__()).put()
    except:
        logging.error('CUSTOM ERROR: Review for restaurant has not been added')

1 个答案:

答案 0 :(得分:1)

我建议通过调用 raise

来重新抛出错误
try:
    RestaurantReview(owned_by=restaurant, written_by=user[0], content=restaurant_review_content.__str__()).put()
except:
    logging.error('CUSTOM ERROR: Review for restaurant has not been added')
    raise