這是給我的行爲,我以後:
if self_instance:
logging.info('creating form with instance so updating the post data, we need this to bind the form so we can validate it')
if post_data:
#update the post data with existing values
for prop in self_instance._properties:
if prop not in post_data:
cur_prop_val = getattr(self_instance, prop)
if isinstance(cur_prop_val,db.Model):
str(cur_prop_val.key())
else:
post_data[prop] = cur_prop_val
else:
logging.info('no post data so not adding it to form')
form_data = form_class(data=post_data,instance=self_instance)
else:
logging.info('creating form without instance')
form_data = form_class(data=post_data)
感謝澄清。有沒有簡單的方法來更新數據? – 2011-05-05 09:55:20