如何在看板视图中查看one2many字段?

时间:2018-03-27 06:51:03

标签: odoo odoo-10

enter image description here我有两个模型 weather_location.weather_location current_weather.current_weather 。在 weather_location.weather_location 中有One2many字段, current_weather.current_weather 有Many2one字段。现在,我想显示 weather_location.weather_location 的看板视图中的字段,这些字段在 current_weather.current_weather 中声明。 在这里,附上我试过的代码:

class location(models.Model):
    _name = 'location.location'

    name = fields.Char(string="City Name")
    location_ids = fields.One2many('weather.weather', 
                    'weather_id', string="Weather Details")
api_address = "http://api.openweathermap.org/data/2.5/weather?appid=6784429f5eff661309aaa5280a143f97&q="

def get_weather_data(self):
    url = self.api_address + self.name
    json_data = requests.get(url).json()
    formatted_data = json_data['weather'][0]['main'] 
    formatted_data1 = json_data['main']['temp']
    formatted_data2 = json_data['main']['temp_min']
    formatted_data3 = json_data['main']['temp_max']
    formatted_data4 = json_data['main']['humidity']
    self.env['weather.weather'].create(
                {'weather_id':self.id,
                 'main':formatted_data,
                 'temp':formatted_data1,
                 'temp_min':formatted_data2,
                 'temp_max':formatted_data3,
                 'humidity':formatted_data4,
                })
class current_weather(models.Model):
    _name = 'weather.weather'

    weather_id = fields.Many2one('location.location', 
            string="Weather",)
    color = fields.Integer()
    main = fields.Char(string="Main")
    temp = fields.Float(string="Temperature")
    temp_min = fields.Float(string="Minimum Temperature")
    temp_max = fields.Float(string="Maximum Temperature")
    humidity = fields.Float(string="Humidity")

.xml文件(看板视图):

<record model="ir.ui.view" id="current_location_Kanban">
      <field name="name">current_weather kanban</field>
      <field name="model">location.location</field>
      <field name="type">kanban</field>
      <field name="arch" type="xml">
        <kanban default_group_by="name">
          <field name="name"/>
                <templates>
                    <t t-name="kanban-box">
                        <div t-attf-class="oe_kanban_content">
                            Main:
                            <!-- <field name="main"/> -->
                            <br/>
                            Temperature:
                            <!-- <field name="temp"/> -->
                            <br/>
                            Minimum Temperature:
                            <!-- <field name="temp_min"/> -->
                            <br/>
                            Maximum Temperature
                            <!-- <field name="temp_max"/> -->
                            <br/>
                            Humidity:
                            <!-- <field name="humidity"/> -->
                        </div>
                    </t>
                </templates>
        </kanban>
      </field>
    </record>

通过使用此标签,不会显示标签的值。如何访问他们的价值

2 个答案:

答案 0 :(得分:0)

<record model="ir.ui.view" id="current_location_form_view">
  <field name="name">current_weather form</field>
  <field name="model">location.location</field>
  <field name="arch" type="xml">
    <form string="Idea Form">
      <header>
          <button string="Get Weather Data" type="object" name="get_weather_data" class="oe_highlight"/>
      </header>
      <sheet>
          <group>
              <field name="name"/>
          </group>
          <notebook>
            <page string="Weather Deatils">
                <field name="location_ids">
                  <tree string="Weather Tree">
                    <field name='main'/>
                    <field name='temp'/>
                    <field name='temp_min'/>
                    <field name='temp_max'/>
                    <field name='humidity'/>
                  </tree>
                </field>
            </page>
          </notebook>
      </sheet>
    </form>
  </field>
</record>

答案 1 :(得分:0)

df3 = pd.DataFrame(Dataset2015)
df3['year'] = '2015'
df4 = pd.DataFrame(Dataset2010)
df4['year'] = '2010'
df5 = pd.DataFrame(Dataset2005)
df5['year'] = '2005'
df6 = pd.DataFrame(Dataset2000)
df6['year'] = '2000'
df7 = pd.concat([df3,df4,df5,df6])
sns.factorplot(errcolor=".2", edgecolor=".2", data = df, hue='country', x='year', y='Mental Health Issues per 100,000 Population', kind='bar', ci=None, aspect=3, size=7);
plt.title('Mental Health Issues in Colombia')
plt.xticks(rotation=45);
plt.show()