'cannot update field of a model in odoo 14
i need a help, what i want to do is to create a method for action button to fetch data from other application api and then update a field in my odoo model with fetched data. this is my code
from odoo import api, fields, models, exceptions
import requests
class MySuperhero(models.Model):
_name = "my.superhero"
name = fields.Char(required=True)
description = fields.Text()
def action_djbc_process(self):
myname = self.name
url = "https://superhero-search.p.rapidapi.com/api/"
querystring = "{'hero':'" + myname + "'}"
headers = {
'x-rapidapi-host': "superhero-search.p.rapidapi.com",
'x-rapidapi-key': "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
response = requests.get(url, headers=headers, params=querystring )
time.sleep(3)
hero = response.json().get('name')
intelligence = response.json().get('powerstats').get('intelligence')
self.description = hero + " " + str(intelligence)
return True
but why get same fetched data and not updated the field, but if i fetch data using curl, the fetched data can change based on querystring ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
