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..
🙂
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.
- [Answer]-How to rotate photos in a div in django-cms
- [Answer]-Django other_dict Error
- [Answer]-Django – Create Category Views doesn't create Column
- [Answer]-Unable to host Django app on Google Cloud Platform
Source:stackexchange.com