我想知道,更新多个字段的标准方法是什么,其中包括 django 中模型实例的相关字段?...
Class User(models.Model):
id = models.CharField()
name = models.CharField()
dob = models.CharField()
Class Appointment(models.Model):
user = models.ForeignKey(User)
app_id = models.CharField()
time = models.DateTimeField()
status = models.CharField()
要更新约会模型中的多个字段,我可以这样做
dict ={
"app_id": "123",
"time": "2012-01-01 10:30",
"status": "Open"
}
Appointment.objects.filter(app_id=123).update(dict)
有没有办法更新相关模型?如何更新约会模型和用户模型?
案子:
dict ={
"name": "foo",
"app_id": "123",
"time": "2012-01-01 10:30",
"status": "Open"
}