title: Create a model from YAML/JSON on the fly
body: <p>I am trying out <a href="http://mongoengine.org">MongoEngine</a>, a DRM library for Python to use with MongoDB. I can define a model like this example from the site:</p>
  
  <pre><code>class User(Document):
      email = StringField(required=True)
      first_name = StringField(max_length=50)
      last_name = StringField(max_length=50)
  </code></pre>
  
  <p>It works like a charm and MongoEngine is really nice. Well, I want to go further and wonder if I can define my models somewhere in a file in JSON or YAML, or whatever so that then create a model using it. So this declaration could look like this in JSON:</p>
  
  <pre><code>{
      "model":"User",
      "fields":{
          "email":{
              "type":"string",
              "required":"true"
          },
          "first_name":{
              "type":"string",
              "max_length":"50"
          },
          "last_name":{
              "type":"string",
              "max_length":"50"
          }
      }
  }
  </code></pre>
  
  <p>Then I would parse this JSON and create a model using it. May be it could be just a single import operation that I would perform each time I modify the model definition, or may be it could parse the whole JSON every time. Is that a good scenario? I just want to let people who will use the app define their own models without having to dig into the code. Any ideas how to do dynamic model creation are appreciated</p>