Hi as we have a json type field in newer versions of odoo for adding analytic accounts etc.
My question is that how we can read and write data in this field with python?
Thankyou
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hi as we have a json type field in newer versions of odoo for adding analytic accounts etc.
My question is that how we can read and write data in this field with python?
Thankyou
Hello,
In Odoo, JSON fields are used to store structured data in JSON format. To read and write data to a JSON field in Python, you can use the following approach:
1.Reading data from a JSON field:
# Assuming you have a model called 'my.model' with a JSON field called 'json_field'
record = self.env['my.model'].browse(record_id)
json_data = record.json_field # This will return a dictionary
2. Writing data to a JSON field:
# Assuming you have a model called 'my.model' with a JSON field called 'json_field'
record = self.env['my.model'].browse(record_id)
# Update the JSON field with new data
record.json_field = {'key': 'value', 'key2': 'value2'}
Hope it helps.
You can also try to modify specific keys in the existing JSON data in the following way:
record.json_field['key2'] = 'value3'
give it a try. Credits to ChatGPT.
Hi, do you know an easy way to update an existing key in the field or add a new one?
This doesn't seem to work and I had to use an extra dict
record.json_field['key_to_update'] = 'new value'
Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!
Zarejestruj sięPowiązane posty | Odpowiedzi | Widoki | Czynność | |
---|---|---|---|---|
|
4
maj 25
|
2035 | ||
|
2
maj 25
|
5336 | ||
|
1
mar 25
|
1293 | ||
|
4
mar 25
|
4063 | ||
|
3
lut 25
|
4965 |