I think you can use model.object.get_or_create()
and like this:
   patient,err = Patient.obiect.get_or_create(kwgs)
   if the object existed,the returned will be wrong, if not ,it will be 
true,
and then you update this instence.

在 2018年5月29日星期二 UTC+8下午7:41:29,Albin Antony写道:
>
> Hello guys,
> Sorry about the above no subject mail
> I am getting a json string(json_string) from frontend. How can we update 
> the django database in views.py. Below is my models.py.
>  
> models.py
>
> class Patient(models.Model):
>     patient_id = models.CharField(primary_key=True, max_length=200)
>     patient_age = models.CharField(max_length=200)
>     patient_name = models.CharField(max_length=200)
>     patient_refby = models.CharField(max_length=200)
>     patient_gender = models.CharField(max_length=20,
>                                       default=Gender.UNKNOWN.value)
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bbe6f91b-4529-4332-8a56-3d909a1da430%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to