Matt Norris
Matt Norris

Reputation: 8836

Update App Engine model with dictionary

You can create a new model in App Engine using a dictionary:

my_model = MyModel.get_or_insert(keyname, **kwargs)

Is there a way to update a model using a dictionary instead of doing the following?

my_model.firstprop = 'first'
my_model.secondprop = 'second'

Upvotes: 2

Views: 534

Answers (1)

Nick Johnson
Nick Johnson

Reputation: 101149

There's no built in method to do this, but writing your own is straightforward:

def update_model(model, values):
  for k, v in values.iteritems():
    setattr(model, k, v)

Upvotes: 6

Related Questions