【问题标题】:Check for duplicates on a repeated property in ndb, appengine检查 ndb、appengine 中重复属性的重复项
【发布时间】:2013-06-25 06:21:55
【问题描述】:

我使用ndb.JsonPropertyrepeated = True 将python dicts 列表存储为ndb 实体。我喜欢该列表不包含重复项。我认为使用类似以下的方法会起作用

    stored_list = TheList(id=list_id)
    current_list = stored_list.list_data
    current_list.extend(items) #items is a list of dicts that need to be newly added

    # check if the list contains duplicate items
    if len(current_list)!=len(set(current_list)):
        cached_list.list_data = current_list
        cached_list.put()

但是set(current_list) 不起作用,因为 dicts 不可散列。我发现some other python solutions 可以做到这一点,但我认为 ndb 可能包含一些功能来防止包含重复对象的重复属性。 Doc 此处不包含此类信息。

所以我的问题是,如何防止重复的 ndb 属性包含重复项?

【问题讨论】:

    标签: google-app-engine app-engine-ndb


    【解决方案1】:

    没有 NDB 功能支持保持重复属性不重复。您可能想提交一个带有 Python 标签的单独问题,询问如何在 Python 中执行此操作。但这将是 O(N**2)。

    【讨论】:

    • 谢谢 Guido,我将使用我找到的 Python 解决方案之一。接受您的回答,因为没有更好的解决方案。
    猜你喜欢
    • 2014-06-12
    • 2012-12-26
    • 2012-07-20
    • 1970-01-01
    • 2013-01-21
    • 2021-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多