存储用户“朋友”在 GAE 数据存储中

发布于 2024-10-30 16:02:18 字数 761 浏览 4 评论 0原文

我正在尝试使用 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 技术交流群。

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

发布评论

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

评论(2

甜宝宝 2024-11-06 16:02:18

我认为你正在尝试的事情没有什么可混淆的。在您的模型中,友谊类具有两个用户属性类型的引用。

freindship=FriendShip()
friendship.user1=#assign a key of user or user object
friendship.user2=#assign a key of user or user object
friendhsip.put()

这里 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.

freindship=FriendShip()
friendship.user1=#assign a key of user or user object
friendship.user2=#assign a key of user or user object
friendhsip.put()

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

脸赞 2024-11-06 16:02:18

我建议您将 userid 也存储在友谊模型中,因为这在相应过滤数据的情况下会很有用...否则您需要爬行数据存储以找到共同的朋友... :D

和“何时”实体也可以按排序顺序显示朋友...:)

class Friendship(db.Model):
  user1 = db.ReferenceProperty(User)
  user2 = db.ReferenceProperty(User)
  user1id = db.StringProperty()
  user2id = db.StringProperty()
  request_accepted = db.BooleanProperty()
  when = db.DateTimeProperty()

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... :)

class Friendship(db.Model):
  user1 = db.ReferenceProperty(User)
  user2 = db.ReferenceProperty(User)
  user1id = db.StringProperty()
  user2id = db.StringProperty()
  request_accepted = db.BooleanProperty()
  when = db.DateTimeProperty()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文