假设我有一个博客文章和评论的博客应用程序。为了争论的缘故,可以有大量的评论,足够大以至于简单的comments = StringProperty(repeated=True
)是不够的。Google App Engine - JSONProperty vs独立模型
我应存储的意见作为JSONProperty(从Python列表连载):
class BlogPost(ndb.Model):
title = ndb.StringProperty()
description = ndb.TextProperty()
comments = ndb.JSONProperty()
或者我应该干脆创建一个单独的评价模型和相应的网志文章的ID存储为一个属性:
class Comment(ndb.Model):
text = ndb.TextProperty()
blog_id = ndb.IntegerProperty()
created = ndb.DateTimeProperty(auto_now_add=True)
我可以查询特定博客帖子的所有评论,如下所示:query = Comment.query(Comment.blog_id==blog_id).order(-Comment.created)
?
一种方法是否可取?特别是如果评论可能会变得非常大> 1000.
非常感谢!在评论模型中,如果我将blog_id属性设置为字符串,可以吗?出于某种原因,我在iOS中使用长数字iD出现错误。这不会有什么区别吗? – JK140
不,无所谓,但为了简单起见,我会保留一个整数并修复iOS中发生的任何事情。 –