def syncdb(): import models from lib.utils import find_subclasses mods = find_subclasses(models.BaseModel) for model in mods: if model.table_exists(): model.drop_table() model.create_table() print 'created table:',model._meta.db_table with open("./qqlist") as qqlist: for name_qq in qqlist: pname, pqq = name_qq.split(',') #print pname, ':', pqq.strip() models.Person.create(name = pname, qq = pqq.strip(), login_times = 0)
def sync_db(): """sync db """ # firstly, import all modules of model.db package prefix = model.db.__name__ + "." for importer, modname, ispkg in pkgutil.iter_modules(model.db.__path__, prefix): __import__(modname) # then, find all subclasses of WARSHIP_DB.Model models = find_subclasses(ZKDASH_DB.Model) for mod in models: if mod.table_exists(): print "table exists: %s, drop it!" % mod._meta.db_table mod.drop_table() mod.create_table() print "created table: %s" % mod._meta.db_table