So I'm trying to fill a One2many list by default. I've defined a basic field, read the "special commands" for One2many and Many2many's but it doesn't seem to work for some reason (no error message or whatsoever, just doesn't fill it)
My code:
@api.one
def _get_competitions(self):
result = []
values = {'name': 'test', 'xx_price': 550, 'xx_seats_left': 50, 'xx_attending': True}
result.append((0, 0, values))
return result
xx_competitions_attendee = fields.One2many('xx.competition.attendee', 'xx_event_id', string="Competitions", default=_get_competitions)
Reworked it a bit and now I'm just returning a search result and still the list doesn't get filled:
@api.model
def _get_competitions(self):
return self.env['xx.competition.attendee'].search([('xx_event_id.id', '=', self._context.get('active_ids')[0])])
xx_competitions_attendee = fields.One2many('xx.competition.attendee', 'xx_event_id', string="Competitions", default=_get_competitions)
I've already set the Many2one relation in the other model, I didn't think it was of great importance that I should post it here, but to be sure:
class CompetitionAttendee(models.Model):
_name = 'xx.competition.attendee'
xx_event_id = fields.Many2one('event.event', string="Event")