python - How to remove a single item in StructuredProperty ( or Repeated Property) of an NDB database? -
i have ndb.model contains 1 repeated property in it.
class resort(ndb.model): name = ndb.stringproperty() hotel_keys = ndb.keyproperty(repeated=true)
i put list of "keys" "hotel_keys" property. need delete single item in (let's id) how that?
resort = resort.get_by_id(resort_id) hotel_key in resort.hotel.keys: if hotel_key.id() == id: del ??? resort.put()
i appreciate help. thanks.
the repeated property list, , entity putting in list simple. can use pop , index rather looping. put()
dev~fish-and-lily> class resort(ndb.model): ... hotel_keys = ndb.keyproperty(repeated=true) ... dev~xxx-and-zzz> y = xx() dev~xxx-and-zzz> y.hotel_keys.append(ndb.key('abc',1)) dev~xxx-and-zzz> y.hotel_keys.append(ndb.key('abc',2)) dev~xxx-and-zzz> y.hotel_keys.append(ndb.key('abc',3)) dev~xxx-and-zzz> y.hotel_keys.index(ndb.key('abc',3)) 2 dev~xxx-and-zzz> y.hotel_keys.pop(2) key('abc', 3) dev~xxx-and-zzz> y.hotel_keys [key('abc', 1), key('abc', 2)] dev~xxx-and-zzz>
Comments
Post a Comment