Django 模型在保存后不持久
我正在设置 FK 字段并保存,但正如您在跟踪日志中看到的那样,如果我检索对象,它的 FK 字段将返回到其预先保存的值,则保存似乎不会保留在数据库中。
型号代码
def do_transition(self, workflow_aware=None):
ws = WorkflowState.objects.get(state=self.transition_to_state, workflow=workflow_aware.workflow)
logging.debug("WorkflowState=%s" % ws)
workflow_aware.current_state = ws
workflow_aware.save()
logging.debug(workflow_aware.current_state)
activitycontent = workflow_aware.__class__.objects.get(pk=workflow_aware.pk)
logging.debug(activitycontent.current_state)
跟踪日志
- DEBUG - WorkflowState=ActivityContent_Workflow_Submitted
- INFO - programcreator.base.models save()
- INFO - programcreator.groupflow.models save()
- DEBUG - ActivityContent_Workflow_Submitted
- DEBUG - ActivityContent_Workflow_Draft
I am setting a FK field and saving, but as you can see in the trace log the save doesn't seem to persist in the DB if I retrieve the object it's FK field returns to it's pre-saved value.
Model code
def do_transition(self, workflow_aware=None):
ws = WorkflowState.objects.get(state=self.transition_to_state, workflow=workflow_aware.workflow)
logging.debug("WorkflowState=%s" % ws)
workflow_aware.current_state = ws
workflow_aware.save()
logging.debug(workflow_aware.current_state)
activitycontent = workflow_aware.__class__.objects.get(pk=workflow_aware.pk)
logging.debug(activitycontent.current_state)
Trace log
- DEBUG - WorkflowState=ActivityContent_Workflow_Submitted
- INFO - programcreator.base.models save()
- INFO - programcreator.groupflow.models save()
- DEBUG - ActivityContent_Workflow_Submitted
- DEBUG - ActivityContent_Workflow_Draft
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论