Django model form save (multi database) question

穿精又带淫゛_ 提交于 2019-12-30 13:27:39

问题


another noob Django question. The below both work for me, is there any difference or anything I should be aware of ? I'm using Django 1.2.5. Thanks.

o = Staff()
form = StaffForm(request.POST, instance=o)

if form.is_valid():
  o.save(using='dbName')


o = Staff()
form = StaffForm(request.POST, instance=o)

if form.is_valid():
  f = form.save(commit = False)
  f.save(using='dbName')

回答1:


The first example does not work - it doesn't update the instance from the form. Use the second.



来源:https://stackoverflow.com/questions/6118884/django-model-form-save-multi-database-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!