update mysql data through django
I have read the djang开发者_开发技巧o tutorial, bit can't understand how to update a mysql record in django. My model and code is show below. I'm trying to update all values which are entered by user in form.
class PatientInfo(models.Model):
name = models.CharField(max_length=200)
uhid = models.CharField(max_length=200)
age = models.IntegerField()
gender = models.CharField(max_length=200)
UPDATE CODE:
patient_edit = PatientInfo.objects.get(id__exact=patient_id)
PatientInfo.objects.filter(address=patient)update(patient_edit)
see the docs at - http://docs.djangoproject.com/en/dev/topics/db/queries/#saving-changes-to-objects
If you wanted to change the name of a patient_edit
patient_edit = PatientInfo.objects.get(id=patient_id) # object to update
patient_edit.name = 'New name' # update name
patient_edit.save() # save object
or basic form docs at - http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method
精彩评论