Как сделать объединение более чем двух таблиц с помощью Django?

Я смог понять, как объединить 2 таблицы с помощью следующего оператора, который отлично сработал для меня, но я не могу понять, как сделать это с 3 таблицами.

Для 2 таблиц

    trailers = TrailerLocation.objects.all().values('trailer__trailerNumber', 'trailer__trailerPlateNumber',
                                                    'trailer__trailerPlateState', 'trailer__trailerLeaseCompany',
                                                    'locationCity', 'locationState', 'locationCountry','statusCode',
                                                    'trailer__id')

Теперь ниже приведены 3 модели, для которых я хочу сделать оператор join.

Отгрузка

class Shipment(models.Model):
    CARRIER_CHOICES = [
        ('GW', 'Greatwide'),
        ('BL', 'Brian Williams'),
    ]
    dateTendered = models.DateField()
    loadNumber = models.CharField(max_length=50)
    masterBolNumber = models.CharField(max_length=50)
    carrier = models.CharField(max_length=100, blank=True, choices=CARRIER_CHOICES)
    destinationCity = models.CharField(max_length=70)
    destinationState = models.CharField(max_length=50)
    rateLineHaul = models.DecimalField(max_digits=15, decimal_places=2)
    rateFSC = models.DecimalField(max_digits=15, decimal_places=2)
    rateExtras = models.DecimalField(max_digits=15, decimal_places=2, default=0.00)
    rateTotal = models.DecimalField(max_digits=15, decimal_places=2, blank=True, null=True)
    loadDelivered = models.BooleanField(default=False)
    customCarrierRate = models.BooleanField(default=False)
    trailer = models.ForeignKey(Trailer, on_delete=models.PROTECT, blank=True, null=True)
    id = models.UUIDField(default=uuid.uuid4, unique=True, primary_key=True, editable=False)

CarrierRate

class CarrierRate(models.Model):
    shipment = models.OneToOneField(Shipment, on_delete=models.PROTECT, primary_key=True)
    rateLineHaulCarrier = models.DecimalField(max_digits=15, decimal_places=2, null=True, default=0.00)
    rateFSCCarrier = models.DecimalField(max_digits=15, decimal_places=2, null=True, default=0.00)
    rateExtrasCarrier = models.DecimalField(max_digits=15, decimal_places=2, null=True, default=0.00)
    rateTotalCarrier = models.DecimalField(max_digits=15, decimal_places=2, null=True, default=0.00)

Маржа отгрузки

class ShipmentMargin(models.Model):
    shipment = models.OneToOneField(Shipment, on_delete=models.PROTECT, primary_key=True)
    shipmentMargin = models.DecimalField(max_digits=15, decimal_places=2, null=True)
    shipmentMarginPercentage = models.DecimalField(max_digits=15, decimal_places=3, null=True)

Мне нужен доступ ко всем полям во всех 3 моделях, поэтому мой возможный jinga код будет иметь вид

                            {% for shipment in shipments %}
                            <tr>
                                <td class="text-center">{{ shipment.dateTendered}}</td>
                                <td class="text-center">{{ shipment.loadNumber }}</td>
                                <td class="text-center">{{ shipment.masterBolNumber}}</td>
                                <td class="text-center">{{ shipment.carrier }}</td>
                                <td class="text-center">{{ shipment.destinationCity }}</td>
                                <td class="text-center">{{ shipment.destinationState }}</td>
                                <td class="text-center">${{ shipment.rateLineHaul }}</td>
                                <td class="text-center">${{ shipment.rateTotal}}</td>
Вернуться на верх