是否有可能使 name=db.StringProperty(unique=True) ?...任何其他方式使其独一无二。?
1 回答
The get_or_insert
will ensure uniqueness of the record via it's key.
Model.get_or_insert (key_name, **kwds)
Attempts to get the entity of the model's kind with the given key name. If it exists, get_or_insert() simply returns it. If it doesn't exist, a new entity with the given kind, name, and parameters in kwds is created, stored, and returned. The get and subsequent (possible) put operations are wrapped in a transaction to ensure atomicity. Ths means that get_or_insert() will never overwrite an existing entity, and will insert a new entity if and only if no entity with the given kind and name exists.