1
我在想,什麼是更新多個領域的標準方式,其中包括在Django模型的實例的相關領域? ...如何更新包含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"
}