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)
)
--
Ticket URL: <https://code.djangoproject.com/ticket/34589>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> 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)
> )
New description:
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)
)
}}}
--
Comment (by David Sanders):
formatted description
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:1>
* status: new => closed
* resolution: => invalid
Comment:
It's not clear to me what you're trying to report, however, it appears to
be a support question. If you're having trouble understanding how Django
works, see TicketClosingReasons/UseSupportChannels for ways to get help.
If you believe there is an issue in Django, then please follow our
[https://docs.djangoproject.com/en/dev/internals/contributing/bugs-and-
features/#reporting-bugs bug reporting guidelines] and include a clear,
concise description of the problem.
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:2>
Comment (by David Sanders):
Also I just tested exclude with nested fks and it's working ok.
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:3>
* version: 4.2 => 4.1
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:4>
* keywords: => 4.1
* version: 4.1 => 4.2
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:5>
* status: closed => new
* resolution: invalid =>
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:6>
* status: new => closed
* resolution: => invalid
Comment:
Hi ftamy9
Please don't reopen the ticket unless more information is provided. You'll
need to paste your models (only the necessary bits required for testing) +
the query you tried that wasn't working.
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:7>
Old description:
New description:
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 fix
--
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:8>
Old description:
> There is a problem on exclude. you can not use nested ForeignKey. I
New description:
}}}
the objects.exclude bug need to fixed
--
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:9>
Comment (by Simon Charette):
There are a few known limitations / bugs with `exclude` (#14645, #27867,
#25991) that could be the cause here but it's impossible to tell without
the exact model definition and test setup to reproduce.
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:10>
* Attachment "trip.py" added.
--
Ticket URL: <https://code.djangoproject.com/ticket/34589>
* Attachment "shipment.py" added.
* Attachment "method.py" added.
* status: closed => new
* resolution: invalid =>
Comment:
the model files attached
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:11>
* status: new => closed
* resolution: => invalid
Comment:
The following query works for me:
{{{
working_shipments = Shipment.objects.exclude(
trip__method__title=ShippingChoice.ORGANIZATION
).filter(
updated_at__lt=datetime.datetime.now(),
)
}}}
Again, please try to use support channels.
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:12>