[Answer]-When i try to update form in django getting this type issue

1👍

Please use json to store dict or list in db

for e.g.

while storing

obj = json.dumps("{
    'PatientProfile__is_recruiter': '1', 
    'PatientProfile__partner': 'FMCS', 
    'PatientProfile__health_insurance_provider': 'MILITARY/VA', 
    'PatientProfile__has_medical_home': '0', 
    'PatientProfile__medical_history_heart_disease': '0', 
    'PatientProfile__medical_history_hypertension': '0', 
    'data_model_name': [
        'PatientProfile'
    ]
}")

and store json obj i.e obj

and while retrieving use

json.loads

So you will get as it is, which you saved previously in db..

🙂

👤Nilesh

0👍

Use json.dumps while storing :

obj = json.dumps("{
'PatientProfile__is_recruiter': '1', 
'PatientProfile__partner': 'FMCS', 
'PatientProfile__health_insurance_provider': 'MILITARY/VA', 
'PatientProfile__has_medical_home': '0', 
'PatientProfile__medical_history_heart_disease': '0', 
'PatientProfile__medical_history_hypertension': '0', 
'data_model_name': ['PatientProfile']
}")

While retrieving you have two options i.e;

Example:

>>>simplejson.loads('{"x":"y"}') 
{'x': 'y'}


>>> json.loads('{"x":"y"}') 
{u'x': u'y'} 

i.e. simplejson returns bytestrings if the string is ASCII (it returns
unicode objects otherwise), while json returns unicode objects always.

👤psorab

Leave a comment