有没有更简单的方法在 AppEngine 中使用 Django Forms 进行唯一性验证?
我知道如果我们保持唯一性约束,性能会出现问题,但由于添加的数据量非常小,性能并不是一个大问题,开发时间才是一个问题。
感谢任何帮助。
最佳答案
您可以使用键来实现唯一性:
The complete key of an entity, including the path, the kind and the name or numeric ID, is unique and specific to that entity. The complete key is assigned when the entity is created in the datastore, and none of its parts can change...
Every entity has an identifier. An application can assign its own identifier for use in the key by giving the instance constructor a key_name argument (a str value):
s = Story(key_name="xzy123")
...Once the entity has been created, its ID or name cannot be changed.
编辑
正如 jbochi 所指出的,这可能很危险,您可能会丢失数据。实现相同目标的另一种方法是使用带有分片计数器的哈希函数。 "Paging through large datasets" 中显示了一个很好的例子文章。
关于python - App Engine Django 表单唯一性验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2753623/