Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
3569 Представления

Hi,

I want to display the numbers according to the id of each user, but I get this error : 'Infotel' object is not iterable

My code is the following

controllers.py

from odoo import http from odoo import api

class Infotel(http.Controller):
    @http.route('/infotel/infotel/', auth='user', website=True)
    @api.one
    def index(self, **kw):
        Infotels = http.request.env['infotel.numbers']
        return http.request.render('infotel.index', {
            'numbers': Infotels.search([])
        })

models.py

from odoo import models, fields, api

class Infotels(models.Model):
    _name = 'infotel.numbers'

    name = fields.Char()
    validite = fields.Char()
    user_id = fields.Many2one('res.users', string="User")

template.xml

<t t-foreach="numbers" t-as="number">
              <option t-att-value="number.id" t-att-selected="numbers.user_id == res.users.id">
                           <t t-esc="number.name" />
               </option>
 </t>


Regards

Аватар
Отменить
Лучший ответ

Hi Alvin,

Please change the template like this, you have to use numbers.user_id.id instead of the numbers.user_id.

<t t-foreach="numbers" t-as="number">
      <option t-att-value="number.id" t-att-selected="numbers.user_id.id == res.users.id">
           <t t-esc="number.name" />
      </option>

</t>

Thanks

Аватар
Отменить
Автор Лучший ответ

Thanks for your reply

i changed my template but i got the same error


Regards

Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
июл. 24
4173
3
апр. 24
4876
0
сент. 21
1942
1
мар. 15
4745
1
окт. 23
2818