python - 谷歌应用程序引擎Python : Know if an entity has been 'seen' by a user

标签 python google-app-engine app-engine-ndb

如果您使用消息应用程序(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/

相关文章:

java - 以增量方式显示数据库查询结果

google-app-engine - 自动 NDB 缓存如何工作?

google-app-engine - 为什么不从 NDB 的上下文缓存中获取实体?

Python HTTP 服务器无法在 Windows 服务内发送响应

Python matplotlib - 两个图表而不是一个

java - 我怎样才能告诉GAE缓存外部图像

google-app-engine - Google App Engine - 将现有的 NDB 属性升级为重复的结构化属性

python - PySpark:使用 newAPIHadoopFile 从多行记录文本文件中读取、映射和减少

python - 完整性错误 : null value in column "city_id " violates not-null constraint

google-app-engine - Google App Engine 上的 SSL 信任证书