how to delete NDB entity using ID?
Asked Answered
P

1

6

based on this docs https://developers.google.com/appengine/docs/python/ndb/entities#deleting_entities well, im still not sure why i cannot do the delete on NDB:

def get(self):
  id = self.request.get("delete")
  ndb.Key('category', id).delete()

yeah i know how to select using id

ndb.Key('category', id).get()

but its still not working...

key = ndb.Key('category', id).get()
key.delete()

this one also not working:

category.key.delete()

something wrong?

Pegmatite answered 14/8, 2012 at 8:55 Comment(0)
D
12

Try this:

ndb.Key(category, int(id)).delete()

You need to convert the id to integer in order to build a numeric (id) key instead of a name key.

Duren answered 14/8, 2012 at 9:3 Comment(2)
Just curious, doesn't ndb allow us to have string ids? Is not related to the question perhaps, and this already solved his problem.Angellaangelle
@Angellaangelle of course, if you want to control the id you need to pass a stringDuren

© 2022 - 2024 — McMap. All rights reserved.