google app engine - How to update one property for multiple NDB entities? -
i have ndb model class below:
class contest(ndb.model): end_date = ndb.dateproperty(required=true, indexed=true) ended = ndb.booleanproperty(required=false, indexed=true) ...
i have daily cron job mark contests passed end_date
ended
equal true
. i've written following code it:
contests = contest.query() current_datetime = datetime.datetime.utcnow() today = datetime.date(current_datetime.year, current_datetime.month, current_datetime.day) contests = contests.filter(contest.end_date < today) contests = contests.filter(contest.ended == false) contests = contests.fetch(limit=10) contest in contests: contest.ended = true ndb.put_multi(contests)
but don't it, since have read entities update 1 value. there way modify read keys_only
?
the object data overwrites existing entity. entire object sent datastore
https://cloud.google.com/datastore/docs/concepts/entities#datastore_updating_an_entity
so cannot send 1 field of entity, "remove" existing fields. more accurate - replace entity fields new version of entity have 1 field.
you have load entities want update, properties, not keys, set new value of property, , put database.
Comments
Post a Comment