如果您使用消息应用程序(Whatsapp、BBM、Facebook Messenger),那么您应该熟悉收件人“看到”您的消息的指示。
我想为我的实体构建此功能。
例如,考虑这个实体(ndb.Model):
class Entity(ndb.Model):
title = ndb.StringProperty()
seen = ndb.BooleanProperty(default = False)
class RenderEntity(BaseHandler):
#renders entity on a template
def get(self, entity_id):
entity = Entity.get_by_id('Entity', entity_id)
self.render('entity_template.html', entity = entity)
这是entity_template.html
<body>
{{entity.title}}
{{entity.seen}}
</body>
如何做到这一点:如果特定用户看到此实体,则 seen
属性将设置为 True?
最佳答案
简单update the Entity
在您看来:
class RenderEntity(BaseHandler):
#renders entity on a template
def get(self, entity_id):
entity = Entity.get_by_id('Entity', entity_id)
# TODO: determine user_id and reciever_user_id
if user_id == receiver_user_id:
entity.seen = True
entity.put()
self.render('entity_template.html', entity = entity)
您没有指定如何确定user_id
,也没有指定如何知道收件人,但一旦获得它们,您可以使用简单的if
测试。
关于python - 谷歌应用程序引擎Python : Know if an entity has been 'seen' by a user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22581120/