Django-ModelFrom中修改save后的字段值

在ModelForm提交中,保持原未修改字段的值,views中部分代码:

project = Iredmail.objects.get(id=id)
ssh_crt_name = project.ssh_crt
if request.method == 'POST':
    file_obj = request.FILES.get("ssh_crt", "")
    i_form = IredmailForm(request.POST,request.FILES,instance=project)
    if i_form.is_valid():
        obj = i_form.save(commit=False)
        if file_obj == "":
            obj.ssh_crt = ssh_crt_name
        obj.save()

 

posted @ 2019-06-24 15:25  温斌  阅读(827)  评论(0编辑  收藏  举报