After reading this, I've realised that fruits analogy is a wrong example of the actual issue I am facing.
I would like to kindly request for some time to read this post.
I'm working on a server project for a petrol station company.
I have this station class.
class Station(modelpy.Model):
shifts = ndb.JsonProperty()
The Station's key's id is the name of a station.
Here are the names of the actual stations: "West Coast", "Woodlands", "South View".
I use these station names in get_by_id() to get the station entity.
As you can see, Station consists of a JsonProperty called "shifts".
The "shifts" consists of the data as follows (shown in a json format):
{
"South View": {
"shifts": {
"Full Day": {
"start": "7am",
"end": "7pm"
}
}
},
"West Coast": {
"shifts": {
"Morning Shift": {
"start": "10am",
"end": "10pm"
},
"Night Shift": {
"start": "10pm",
"end": "10am"
}
}
},
"Woodlands": {
"shifts": {
"Morning Shift": {
"start": "8am",
"end": "8pm"
},
"Night Shift": {
"start": "8pm",
"end": "8am"
}
}
}
}
I need a solution for these 3:
1) Ndb must not be allowed to store more than 1 shift (e.g. key.put() replaces any (if existing) entity with equal id).
2) Ndb must contain the "start" and "end" required property for every shift (e.g. required=True).
3) Most IMPORTANT: A MAINTAINTABLE solution that does not need to be re-implemented for other similar examples. (e.g. NOT write custom assertion every single time!)
JsonProperty demands a crap-ton of maintainability
I don't want to write a custom assertion every time, instead I want a generic solution (dictionary).
Don't mind the caps, I'm not shouting at anyone, just emphasis.
Love,
Ryan