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
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞