1
votes

For example: I have an Article model with a repeated "title" property that stores translations in different languages of the original title:

class Article(ndb.Model):
  title = ndb.StringProperty(repeated=True)

How can I store, besides the title property, the language code of the title, so I can get specific versions of the title, something like this:

en_title = article.title['en']

It is important to have the same property name since I don't know in what language the article title will be queried by.

2

2 Answers

3
votes

You can use repeated structure property:

class Title(ndb.Model):
  title = ndb.StringProperty()
  lang = ndb.StringProperty()

class Article(ndb.Model):
  titles = ndb.StructuredProperty(Title, repeated=True)
3
votes

Are you querying on the titles or languages? If not, you can use PickleProperty or JsonProperty to store a dict.