Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
5078 Visualizzazioni

I've simplified my code for the sake of this question, but basically I have this  

class Booking(models.Model):
_name = 'ff.booking'
boat_ride_bookings = fields.Many2many('ff.boat_ride_booking')
foo = fields.Integer()

class BoatRideBooking(models.Model):
_name = 'ff.boat_ride_booking'
booking = fields.Many2many('ff.booking')
foo = fields.Integer()

In another place (outside of both of these models) I'm trying to do create some BoatRideBooking objects on existing Booking objects and then connecting them.

This works

# booking is a referance to an existing record
brb = self.env['ff.boat_ride_booking'].create({ 'foo': 1 })
booking.boat_ride_bookings = [(4,brb.id)]

But I want to do something like this

# booking is a referance to an existing record
brb = self.env['ff.boat_ride_booking'].create({ 'foo': 1, 'booking': booking.id })

or even better

# booking is a referance to an existing record
booking.boat_ride_bookings = [(0,0,{ 'foo': 1, 'booking': booking.id }]

but that neither works. I probably don't have the right syntax and I've been looking everywhere and trying a lot.

Someone know the right syntax on how to solve this problem?

Thanks!

Avatar
Abbandona
Risposta migliore

Hi Alf,

In your case you can define declare fields with same table name like following:

class Booking(models.Model):
_name = 'ff.booking'
boat_ride_bookings = fields.Many2many('ff.boat_ride_booking','ff_boat_booking_rel', 'ff_id', 'boat_ride_id', string="field name")
class BoatRideBooking(models.Model):
_name = 'ff.boat_ride_booking'
booking = fields.Many2many('ff.booking','ff_boat_booking_rel', 'boat_ride_id', 'ff_id', string="field name")

Both object Many2many belongs to same table with same column name, just need change the column name places based on objects, and if you create either of any one many2many  other object many2many would connect by same time.


Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
feb 24
1550
0
lug 24
2448
0
lug 22
60
1
lug 22
2418
2
dic 23
32971