数据修改的步骤与插入的步骤大致相同,唯一的区别是在于数据对象来自数据表,因此需要执行一次数据查询。
注:PersonInfo是我定义的模型,PersonInfo包含id,name,age,hireDate4个字段。
>>> from index.models import PersonInfo
>>> p = PersonInfo.objects.get(id=12)
>>> p.age = 100
>>> p.save()
把id=12的age字段改为100,修改成功

除此之外,使用update方法实现数据修改:

>>> p = PersonInfo.objects.filter(name="测试工程师").update(name="运维工程师")

>>> d = dict(name="测试员")
>>> PersonInfo.objects.filter(name="运维工程师").update(**d)
>>> PersonInfo.objects.update(age=99)