Technical mailing list archives

Re: New api: Related fields issue

Maxim Litnitskiy
- 09/25/2014 08:13:13
Sorry all the list for spam :-)
Forgot the magic keywords pause_request = fields.Boolean(related='active_session.pause_request').
Probably I need to sleep more then 3 hours per nignt :-)

2014-09-25 15:54 GMT+04:00 Maxim Litnitskiy <>:
Hi guys!
    def _get_active_session(self):
        """Get open session"""
        session =[
            ('state', 'in', ['running', 'paused'])],
            order='create_date desc', limit=1)
        self.active_session = session
        print 'SESSION', self.active_session
        print 'SESSION PAUSE', self.active_session.pause_request

This code gets the latest session object according to criteria.

To be able to get from views active_session fields I added to the model:

active_session = fields.Many2one('asterisk.dialer.session', compute='_get_active_session')
cancel_request = fields.Boolean('active_session.cancel_request')
pause_request = fields.Boolean('active_session.pause_request')

(I was surpised I cannot do in view: <button name='pause' type='object' string='Pause' attrs="{'invisible': [('active_session.pause_request','!=',True)]}"/>, cannot I chain fields in views?)

But Related field does not work. When there is no active_session self.active_session.pause_request returns False but self.pause_request returns True.
How can it be?