【发布时间】:2013-06-25 06:21:55
【问题描述】:
我使用ndb.JsonProperty 和repeated = 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