I have this sample json of a list of "Fruit":
{
  "apple":{
    "color":red"
    "taste":"sweet"
  }
  "pineapple":{
    "color":yellow"
    "taste":"sour"
  }
}
I want to use a very object oriented approach to retrieve a property of my 
entity using a string key.
The requirements:
1) NDB must not be able to store any "Fruit" without the "color" or "taste" 
fields. (JsonProperty does not meet this requirement)
2) "apple" and "pineapple" are unique identifiers, used to retrieve it's 
corresponding fruit data, NDB must not be able to store multiple fruit 
objects containing the same unique identifier.

class Fruit(ndb.Model):
  name = ndb.StringProperty(required=True)
  color = ndb.StringProperty(required=True)
  taste = ndb.StringProperty(required=True)

class Person(ndb.Model):
  favoritefruits = ndb.StructuredProperty(required=True,repeated=true)

Then to find apple,
person = Person.get_by_id("Johnathan").favouritefruits
for fruit in person.favoritefruits:
  if fruit.name == "apple"
    # found apple!

The problem:
Multiple "Fruit" objects containing the same "name" property can exist in 
the "favoritefruits" property.

What solutions are there that will fulfil both requirements 1) and 2)?

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/a6c7c7f1-d150-4a97-b0f3-639558fedc07%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to