多对多关系 +谷歌数据存储 + Python

发布于 2024-12-02 15:20:40 字数 1043 浏览 2 评论 0原文

给出以下日志:

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()    

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

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')

Given the log of following:

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

and following codes:

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)

When I was trying to create the instance of RestaurantReview, it just never work:

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

EDIT
Any idea what's happening? It keeps throwing the custom error that I set.

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')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌能量女王 2024-12-09 15:20:40

我建议通过调用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

I suggest to rethrow the error by calling 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文