假如您在使用SQLAlchemy的declaratives
,和你的对象名称是对象,你可以使用:
# I suppose you already have your session somehow...
# If you want to add it to the database
# Assuming you did not change the __init__ method
obj = Object(**data_dictionary_with_keys_matching_column_names)
session.add(obj)
# If you want to issue an update
# obj is already there somehow...
for k, v in data_dictionary_with_keys_matching_column_names.iterkeys():
setattr(obj, k, v)
session.commit()
这只是如果你正在使用ORM和声明。 (你提到SQLAlchemy的,所以我想,如果是PostgreSQL的或另外一个它不会改变)
编辑:我想你会在正确的做法,只是确保你使用wx.Validator
为了你们的形式,并存储在一个字典的数据,这是非常实用的。
看起来像这个[问题](http://stackoverflow.com/questions/1378325/python-dicts-in-sqlalchemy) – Boud 2012-04-25 16:59:50
我在下面的文章中这样做:http://www.blog .pythonlibrary.org/2011/11/10/wxPython的和 - SQLAlchemy的-AN-介绍到MVC-和污物/。它可以帮助你找出你自己的方法。 – 2012-04-25 21:11:36
@MikeDriscoll:我很喜欢你的教程,经常关注它。 – 2012-04-26 13:35:43