Why you need a transaction to update just one entity? Just save it and
you may get an exception when update failed.
BTW, DateTimeProperty has an parameter auto_now, you can use it to
automatic update its time by datastore.
And if you really want a transaction, you need fetch it before start
the transaction:
item = C1.gql("WHERE p1 = :a AND p2 < :b ORDER BY p2", a = None, b =
today).get()
if item:
key = item.key()
def update_time(key)
item = C1.get(key)
if item:
item.p1 = now
item.put()
db.run_in_transaction(update_time, key)
2009/11/14 Will <[email protected]>:
> Yes, I've read the document. I'm looking for some examples.
>
> As I said, I have a class, C1, whose entities have no ancestors. I want to
> query a particular entity from it, modify, and put it back, for example,
>
> item = C1.gql("WHERE p1 = :a AND p2 < :b ORDER BY p2", a = None, b =
> today).fetch(1)
> item.p1 = now
> item.put()
>
> Both p1 and p2 are datetime. How can I build this into a transaction? Is
> there a way I can give the entities a 'place holder' ancestor so I can later
> use an 'ancestor filter' in the query to satisfy the requirement?
>
> Thanks,
>
> Will
>
>
> On Fri, Nov 13, 2009 at 9:44 PM, Stephen <[email protected]> wrote:
>>
>> On Nov 13, 2:27 am, Will <[email protected]> wrote:
>> >
>> > Can you give me some examples of 'ancestor queries'? If possible, I'd
>> > like
>> > to change the existing ones into 'ancestor queries' and fit the whole
>> > into a
>> > transaction, because that is exactly what a transaction designed for.
>>
>>
>>
>> http://code.google.com/appengine/docs/python/datastore/transactions.html#What_Can_Be_Done_In_a_Transaction
>>
>> --
>>
>> 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=.
>>
>>
>
> --
>
> 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=.
>
--
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=.