python - App Engine Django 表单唯一性验证?

标签 python google-app-engine django-forms

有没有更简单的方法在 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/

相关文章:

Python/Django 调试 : print model's containing data

python - Holoviz/Param/Panel : is it possible to change, 隐藏或删除保存参数化类参数的参数面板的标题?

python - Brew 未安装最新版本

google-app-engine - UTF-8 字符串被 GAE 上的 ReSTLet 扰乱

java - 从 GAE 连接到 MySQL 实例时出现 CommunicationsException

python - 如何使用每个选择的模板覆盖 ModelChoiceField/ModelMultipleChoiceField 默认小部件

python - 如何使用 TensorFlow 的 `matrix_solve_ls` 排除正则化中的偏差?

java - Google App Engine - 无法在单个事务中对多个实体组进行操作

python - django - 必须至少填写一个表单字段

django - 如何给 `def formfield_for_manytomany` 一个可编辑对象的 id