views:

132

answers:

1

Is there a simpler way to use uniqueness validation with Django Forms in AppEngine?

I understand that performance would be problem if we keep an uniqueness constraint but since the amount of data being added is very small performance is not a big concern, rather development time is a concern here.

Any help is appreciated.

+1  A: 

You can use keys for uniqueness:

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.

EDIT

As jbochi noted, this could be dangerous and you could loss data. Another way to achieve the same is using an hash function with shard counters. A good example is showed in "Paging through large datasets" article.

mg
Beware that the old instance will be overwritten if you try to save a new one with the same `key_name`. No errors will be raised.
jbochi