If two requests want to create an M() they will get the same ID.
You must use some kind of transaction to get unique IDs

2009/4/18 风笑雪 <[email protected]>:
> I use this code to keep an id:
> class M(db.Model):
>   id = db.IntegerProperty()
>   time = db.DateTimeProperty(auto_now_add=True)
>    @staticmethod
>    def max_id():
>     maxID = memcache.get('MaxID')
>     if maxID:
>       return maxID
>     messages = Message.all()
>     messages.order("-id")
>     message = messages.get()
>     if message:
>       return message.id
>     else:
>       return 0
> entity = M()
> entity.id = M.maxID + 1
> entity.put()
> 2009/4/19 David Wilson <[email protected]>
>>
>>
>> thanks! i missed that in the docs :)
>>
>> I wasnt using a datetime just to save a bit of space, but i can see i
>> need to know to guarantee ordering, or if i want to do ordered paging
>> via key i would need to handle key creation myself to make sure they
>> are in order.
>>
>> This becomes harder in one case for me as users can create designs
>> that need to be paged through in creation order. There will be too
>> much contention on a glodal counter for this, so i guess an offset
>> page on date is the best i can do for now. Or just not worry when some
>> 'new designs' are out of order.
>>
>>
>>
>> On Apr 18, 2:20 am, David Symonds <[email protected]> wrote:
>> > On Sat, Apr 18, 2009 at 3:21 PM, David Wilson
>> >
>> > <[email protected]> wrote:
>> > > Is this expected behaviour? and thus do i need to always give a
>> > > key_name to guarantee order? this creates scaling issues for order
>> > > counter (which is probably why its not in order in the backend :) )
>> >
>> > Keys are only guaranteed to be unique, not sequential or in order:
>> >
>> >  http://code.google.com/appengine/docs/python/datastore/keysandentityg...
>> >
>> > What is wrong with giving your models a timestamp property (with
>> > auto_now_add=True), and sorting by that?
>> >
>> > Dave.
>>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to