Opened 18 months ago

Last modified 18 months ago

#34589 closed Bug

exclude does not support nested ForeignKey relationship — at Version 1

Reported by: ftamy9 Owned by: nobody
Component: Database layer (models, ORM) Version: 4.2
Severity: Normal Keywords: 4.1
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by David Sanders)

I need to find trips that are not trip__method__title=ShippingChoice.ORGANIZATION
my code is like this:

    working_shipments = Shipment.objects.exclude(
        state__in=[
            ShipmentStateChoices.CANCELLED,
            ShipmentStateChoices.DELIVERED
        ],
        trip__method__title=ShippingChoice.ORGANIZATION
    ).filter(
        updated_at__lt=time_threshold,
    )

I forced to use a big list on filter instead to use the exclude. my code is like this:

    working_shipments = Shipment.objects.exclude(
        state__in=[
            ShipmentStateChoices.CANCELLED,
            ShipmentStateChoices.DELIVERED
        ]
    ).filter(
        updated_at__lt=time_threshold,
        trip__method__title__in=(ShippingChoice.ALO,  ShippingChoice.SNAP, ShippingChoice.MIAREH)  
    )

Change History (1)

comment:1 by David Sanders, 18 months ago

Description: modified (diff)

formatted description

Note: See TracTickets for help on using tickets.
Back to Top