Created
August 14, 2012 09:10
-
-
Save naoyeye/3347722 to your computer and use it in GitHub Desktop.
web.py中如何批量更新mysql数据?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#controllers部分: | |
class media_describe: | |
@session.login_required | |
def POST(self): | |
f = web.input(image_title=[],image_describe=[],path={}) | |
imageTitle = f.image_title | |
imageDescribe = f.image_describe | |
imagePath = f.path.split(',') | |
image.saveTitleDescribe(imagePath, imageTitle, imageDescribe) #更新数据库 | |
return view.test(imagePath, imageTitle, imageDescribe) | |
#models部分的image.py: | |
def saveTitleDescribe(imagePath, imageTitle, imageDescribe): | |
for p in imagePath: | |
for describe in imageDescribe: | |
db.update('image', vars=dict(path=p), where='path = $path', imageDescribe = describe) | |
for title in imageTitle: | |
db.update('image', vars=dict(path=p), where='path = $path', imageTitle = title) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment