Opened 18 months ago
Closed 18 months ago
#34589 closed Bug (invalid)
exclude does not support nested ForeignKey relationship
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 )
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
Attachments (3)
Change History (15)
comment:1 by , 18 months ago
Description: | modified (diff) |
---|
comment:2 by , 18 months ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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 bug reporting guidelines and include a clear, concise description of the problem.
comment:4 by , 18 months ago
Version: | 4.2 → 4.1 |
---|
comment:5 by , 18 months ago
Keywords: | 4.1 added |
---|---|
Version: | 4.1 → 4.2 |
comment:6 by , 18 months ago
Resolution: | invalid |
---|---|
Status: | closed → new |
comment:7 by , 18 months ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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.
comment:8 by , 18 months ago
Description: | modified (diff) |
---|
comment:9 by , 18 months ago
Description: | modified (diff) |
---|
comment:10 by , 18 months ago
by , 18 months ago
by , 18 months ago
Attachment: | shipment.py added |
---|
by , 18 months ago
comment:12 by , 18 months ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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.
formatted description