Question

I'm creating a database where I have the following hierarchy: Subject -> Topics -> Pages. I know that there will only ever be two subjects. Arts and Science lets say. Is it possible for me to create a topic where I set the parent key to a string "Arts", so that I don't have to create a db.model Subject with only two values?

Also, if I do have to make a class Subject inheriting from db.Model, is there a way I can avoid putting in any parameters since the key.name will be the name of the subject?

Était-ce utile?

La solution

Just specifying an ancestor key is enough, the ancestor itself does not have to exist.

You don't have to provide any properties in a Model.

class MyModel(db.Model):
    pass

And lastly I gather you are just starting out, so I would recommend you switch to ndb before you go to far.

Autres conseils

Tim's answer is correct. I just wanted to add to the answer that it's poor design to have all your entities under two ancestors.

Ancestors exist in cases where you need to ensure transactional integrity. That might be true for you, in which case, ignore this.

The use of ancestors limits the write performance for all entities within that ancestor tree. If you don't really need to lock down all of these entities, you might not actually use an ancestor, but just a normal attribute.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top