E
E
Evgeny Popov2011-08-22 19:09:54
Python
Evgeny Popov, 2011-08-22 19:09:54

Create model in GAE(python) on the fly?

Is it possible to create a “model” (in a sense, “tables”) in an application at run time.
In other words, it is necessary: ​​to create “tables” and assign properties and their types to them from the application form. After creation, get a list of “tables” data and interact with them in the same way as “ordinary” ones:

class Pet(db.Model):
    name = db.StringProperty(required=True)
    type = db.StringProperty(required=True, choices=set(["cat", "dog", "bird"]))
    birthdate = db.DateProperty()
    weight_in_pounds = db.IntegerProperty()
    spayed_or_neutered = db.BooleanProperty()
    owner = db.UserProperty(required=True)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
defuz, 2011-09-27
@defuz

Yes, why not.
newModelClass = type(modelName, (db.Model,), {"name" : db.StringProperty(required=True), ...})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question