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.
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)
Are you querying on the titles or languages? If not, you can use PickleProperty or JsonProperty to store a dict.
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.