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()

 

转载于:https://www.cnblogs.com/sz-wenbin/p/11077303.html

你可能感兴趣的:(python,后端)