I'm trying to figure out how I can navigate, or dot walk, through my relations..
I have a User class. For an instance of user they are connected to accounts, via an account_permission class. So:
class User(models.Model):
# this works fine
accounts = models.ManyToManyField('Account', through='AccountPermission')
class AccountPermission(models.Model):
user = models.ForeignKey('User', on_delete=models.CASCADE, )
account = models.ForeignKey('Account', on_delete=models.CASCADE, )
class Account(models.Model):
pass
class Booking(models.Model):
account = models.ForeignKey('Account', on_delete=models.CASCADE, )
Now what I'm trying to do, is write a method in the User class that will bring me all the booking instances, via all the connected account permissions and then accounts. Kind of a join I guess, but my DB knowledge is not firm enough to figure out if it's a left outer or something.
In RoR from my distant past, I could just chain the throughs, but it doesn't seem to work the same in Django, and I seen to lack the domain language skills to figure it out in google :-(. Any help gratefully recieved.
question from:
https://stackoverflow.com/questions/65829743/django-how-to-can-i-access-all-objects-through-another-through-relation 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…