存储用户“朋友”在 GAE 数据存储中
我正在尝试使用 Flask 和 google 应用程序引擎制作一个 facebook 类型的社交网站(不是 facebook 应用程序)来娱乐。我目前正在研究如何在数据存储中存储朋友。
我希望它有点像 Facebook,因为一个用户会请求成为另一个人的朋友,一旦被接受,他们就可以看到彼此的帖子。到目前为止,它对我来说似乎是这样存储的:
class Friendship(db.Model):
user1 = db.ReferenceProperty(User)
user2 = db.ReferenceProperty(User)
request_accepted = db.BooleanProperty()
但我看到了 这篇文章stackoverflow 以及 Google 数据存储区文档 这让我很困惑。我以前只使用过像mysql这样的关系数据库,所以我真的不知道它们是怎么回事,但这似乎很重要。
如果有人知道我应该做什么,请告诉我——我将不胜感激。如果您需要我的完整 models.py
源代码,请告诉我。
提前致谢!
I'm trying to make a facebook sort of social networking site (not a facebook app) for fun using flask and google app engine. I'm currently working out how to store friends in the datastore.
I want it to be somewhat like facebook, in that a user will request to be another's friend and once accepted, they can see each other's posts. So far it seems like it would be stored like this to me:
class Friendship(db.Model):
user1 = db.ReferenceProperty(User)
user2 = db.ReferenceProperty(User)
request_accepted = db.BooleanProperty()
but I saw this post on stackoverflow, and the many-to-many example on google's datastore documentation and it has me confused. I have only ever worked with relational databases like mysql before, so I don't really know what they are going on about, but it seems important.
If anyone knows what I should do, please let me know—it would be hugely appreciated. If you need my full models.py
source code, let me know.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你正在尝试的事情没有什么可混淆的。在您的模型中,友谊类具有两个用户属性类型的引用。
这里 user1 和 user2 将引用某个用户对象。还要将集合名称添加到引用属性中以避免混淆。
要了解更多信息,请查看此处appengine 中的建模< /a>
I think what you are trying has nothing to be confused. In your model, an friendship class is having two references of the type user property.
Here user1 and user2 will be referring to some user object. And also add a collection name to your reference attributes to avoid confusion.
To know more have a look here modeling in appengine
我建议您将 userid 也存储在友谊模型中,因为这在相应过滤数据的情况下会很有用...否则您需要爬行数据存储以找到共同的朋友... :D
和“何时”实体也可以按排序顺序显示朋友...:)
I suggest you to have userid also to be store in Friendship model as that will be useful in case of filtering data accordingly... Otherwise you need to crawl your datastore to find mutual friends... :D
And "When" entity too to show friends in sorted order... :)