Skip to content

Instantly share code, notes, and snippets.

@naoyeye
Created August 14, 2012 09:10
Show Gist options
  • Save naoyeye/3347722 to your computer and use it in GitHub Desktop.
Save naoyeye/3347722 to your computer and use it in GitHub Desktop.
web.py中如何批量更新mysql数据?
#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