title: Peewee - How to Convert a Dict into a Model
body: <p>Lets say I have</p>
  
  <pre><code>import peewee
  
  class Foo(Model):
      name = CharField()
  </code></pre>
  
  <p>I would like to do the following:</p>
  
  <pre><code>f = {id:1, name:"bar"}
  foo = Foo.create_from_dict(f)
  </code></pre>
  
  <p>Is this native in Peewee? I was unable to spot anything in the <a href="https://github.com/coleifer/peewee/blob/master/peewee.py" rel="nofollow">source code</a>.</p>
  
  <p>I've wrote this function which works but would rather use the native function if it exists:</p>
  
  <pre><code>#clazz is a string for the name of the Model, i.e. 'Foo'
  def model_from_dict(clazz, dictionary):
       #convert the string into the actual model class
      clazz = reduce(getattr, clazz.split("."), sys.modules[__name__])
      model = clazz()
      for key in dictionary.keys():
      #set the attributes of the model
          model.__dict__['_data'][key] = dictionary[key]
      return model
  </code></pre>
  
  <p>I have a web page that displays all the <code>foo</code>s and allows the user to edit them. I would like to be able to pass a JSON string to the controller, where I would convert it to a dict and then make Foos out of it, so I can update as necessary.</p>