콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
2099 화면
I want to loop through a list and create a field with each item in list 

from odoo import models, fields


class SchoolStaff(models.Model):
_name = 'school.staff'

field_names = ['name', 'age', 'position']
for field in field_names:
locals()[field] = fields.Char()
 id="school_staff_form_view" model="ir.ui.view">
name="name">school.staff.form.view
name="model">school.staff
name="arch" type="xml">



t-foreach="o.field_names" t-as="field">

name="t-esc(field)"/>






아바타
취소
베스트 답변

Hi,

Please refer to the Following Example.

For adding a field in the product form you can try the code below in your function.

inherit_id = self.env.ref('product.product_template_only_form_view')
arch_base = _('<?xml version="1.0"?>'
'<data>'
'<field name="barcode" position="after">'
'<field name="new_field"/>'
'</field>'
'</data>')
self.env['ir.ui.view'].sudo().create({'name': 'product.inherit.fields',
'type': 'form',
'model': 'product.template',
'mode': 'extension',
'inherit_id': inherit_id.id,
'arch_base': arch_base,
'active': True})




Regards

아바타
취소