简体   繁体   中英

How to access Google Cloud Datastore entity with dash in its name?

I am working on a Google App Engine project and I need to access a Datastore entity with a name that contains dash, eg random-entity . I want to do that in Python. Since random-entity is invalid syntax for a class name, I cannot create a model and access it like that.

So how can I access this entity? Is it possible to do that without creating a model and just retrieve it in JSON format?

Keep in mind that renaming the entity is not an option for the project I am working on.

If you are using NDB library you need to override class method _get_kind(cls) of model, like this:

class RandomEntity(ndb.Model):

  @classmethod
  def _get_kind(cls):
    return 'random-entity'

  # You can override property name as well
  random_name = ndb.StringProperty('random-name')

EDIT: Added missing colon after _get_kind

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM