我试图设计表格,以建立跟踪关系。
Saye 我有140个有用户、信使和其他文本的记录。
用户跟着其他用户,也可以跟踪冲锋。
我将概述我如何制定以下目标,但我的设计有两点限制。 我很想知道,其他人是否拥有实现同样目标的更加划时代的方法。
这里的问题是:
- The list of followers is copied in for each record
- If a new follower is added or one removed, all the records have to be updated.
法典
class HashtagFollowers(db.Model):
"""
This table contains the followers for each hashtag
"""
hashtag = db.StringProperty()
followers = db.StringListProperty()
class UserFollowers(db.Model):
"""
This table contains the followers for each user
"""
username = db.StringProperty()
followers = db.StringListProperty()
class stream(db.Model):
"""
This table contains the data stream
"""
username = db.StringProperty()
hashtag = db.StringProperty()
text = db.TextProperty()
def save(self):
"""
On each save all the followers for each hashtag and user
are added into a another table with this record as the parent
"""
super(stream, self).save()
hfs = HashtagFollowers.all().filter("hashtag =", self.hashtag).fetch(10)
for hf in hfs:
sh = streamHashtags(parent=self, followers=hf.followers)
sh.save()
ufs = UserFollowers.all().filter("username =", self.username).fetch(10)
for uf in ufs:
uh = streamUsers(parent=self, followers=uf.followers)
uh.save()
class streamHashtags(db.Model):
"""
The stream record is the parent of this record
"""
followers = db.StringListProperty()
class streamUsers(db.Model):
"""
The stream record is the parent of this record
"""
followers = db.StringListProperty()
Now, to get the stream of followed hastags
indexes = db.GqlQuery("""SELECT __key__ from streamHashtags where followers = myusername """)
keys = [k,parent() for k in indexes[offset:numresults]]
return db.get(keys)
是否有更明智的办法这样做?