Reputation: 1136
I have a project that will need data to be separated.
There will be multiple 'systems' that will be implemented. Each will be based on a general model. To have this in the GAE datastore, I could use a prefix: 4EClass
, 3EClass
and PthClass
. I would rather use the namespaces for this as it seems to be cleaner.
I would like to be able to set a namespace in the kind's subclass:
class Class(db.Model):
namespace = '4E'
Is there a way to get put, query, etc to work with these namespaces preferably without having to do Class.query(namespace=Class.namespace)
or the like?
Upvotes: 0
Views: 87
Reputation: 101149
Using namespaces for this does not make a great deal of sense - namespaces are orthogonal to model classes.
Instead, you can specify a kind name independently of the class name:
class MyModel(db.Model):
@classmethod
def kind(cls):
return "MyModel_Foo"
Upvotes: 1
Reputation: 7158
i think what you are looking for are polymodels. here with ndb: https://developers.google.com/appengine/docs/python/ndb/polymodelclass
or db: https://developers.google.com/appengine/docs/python/datastore/polymodelclass
and i also would suggest you to use ndb
instead of the db
package.
https://developers.google.com/appengine/docs/python/datastore/polymodelclass
Upvotes: 0