How to update fields in a model without creating a new record in django?

后端 未结 5 1661
你的背包
你的背包 2020-12-23 11:14

I have a model in django that I want to update only, that is, when I call it and set the data, it will not create a new record, only update the existing one. How can I do th

5条回答
  •  借酒劲吻你
    2020-12-23 11:57

    In my scenario, I want to update the status of status based on his id

    student_obj = StudentStatus.objects.get(student_id=101)
    student_obj.status= 'Enrolled'
    student_obj.save()
    

    Or If you want the last id from Student_Info table you can use the following.

    student_obj = StudentStatus.objects.get(student_id=StudentInfo.objects.last().id)
    student_obj.status= 'Enrolled'
    student_obj.save()
    

提交回复
热议问题