I am building a web application (Django and google's NDB) and have to structure my models now. I have read many examples about how to implement One-To-Many but - to be honest - I'm even more confused right now after having read these.
Let me describe my problem with a similar example: I have users and each user can read multiple books. A user can stop reading at any time and the progress is saved. Even if a book has been finished, the progress will be saved and never deleted.
I need to check the progress of all books a user has started to read all the time, so this has to be efficient and should require as few db reads as possible. The amount of books is not too much (< 1000) and also the books are thin (say, only one chapter, title, author that's it). It's the mass of progress and the permanent lookup of the progress that I'm fearing since every user has his own progress to probably every book.
How can I structure my models best to these requirements? If I use the StructuredProperty in my User model will the size of the books that are refered to in Progress count towards the limit of X MB (hope not)? If not I guess something like this is the best way to go (I can read progress fast, without additional lookup, and if neccessary get the book from the db).
class Book(ndb.model):
name = ndb.StringProperty(required=True)
...
class Progress(ndb.model):
book = ndb.KeyProperty(kind="Book", required=True)
last_page_read = ndb.IntegerProperty(required=True, default=0)
...
class User(ndb.model):
name = ndb.StringProperty(required=True)
books_and_progress = ndb.StructuredProperty(Progress, repeated=True)
...