I want to be able to give each instance of a particular object a unique number id in the order that they are created, so I was thinking of getting the number of the particular entity already in the datastore and add 1 to get the new number.
I know I can do something like
query = Object.all()
count = query.count()
but that has some limitations.
Does anybody know a better way to find the number of particular entities or even a better way to give objects a unique sequential number id?
Thanks!
Why do your IDs need to be sequential? The App Engine datastore generates integer IDs for your entities already; they’re not guaranteed to be sequential, but they are guaranteed to be unique, and they tend to be small.
The ID generation strategy for App Engine is not ‘perfect’ – entirely sequential – because doing so in a distributed system is impractical, as it introduces a single bottleneck (the service that hands out IDs). Any system you build will suffer from the same issue, unless you want only a low rate of ID issuance (eg, 1 per second or less).