﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34589	exclude does not support nested ForeignKey relationship	ftamy9	nobody	"There is a problem on exclude. you can not use nested ForeignKey. I tested on 4.2.1 and 4.1.
for example if you need to find trips that are not `trip__method__title=ShippingChoice.ORGANIZATION`
Here is the code:

{{{
    working_shipments = Shipment.objects.exclude(
        state__in=[
            ShipmentStateChoices.CANCELLED,
            ShipmentStateChoices.DELIVERED
        ],
        trip__method__title=ShippingChoice.ORGANIZATION
    ).filter(
        updated_at__lt=time_threshold,
    )
}}}

So you are forced to use a big list on filter instead to use the exclude. 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)  
    )

}}}
the objects.exclude bug need to fixed"	Bug	closed	Database layer (models, ORM)	4.2	Normal	invalid	4.1		Unreviewed	0	0	0	0	0	0
