4👍
✅
Try:
user.messages_recieved.filter(response__isnull=True)
the resulting query is:
SELECT "messaging_message"."id", "messaging_message"."sender_id", "messaging_message"."recipient_id", "messaging_message"."subject", "messaging_message"."body" FROM "messaging_message" LEFT OUTER JOIN "messaging_response" ON ("messaging_message"."id" = "messaging_response"."message_id") WHERE ("messaging_message"."recipient_id" = 1 AND "messaging_response"."message_id" IS NULL)
which I think is proper. It is indeed doing the left outer join and then checking for rows with null response message id.
u.messages_recieved.filter(response=None)
works fine too.
I’m using django 1.1 RC but this should work in 1.0+.
3👍
Something that I’ve done when trying to achieve a similar result is:
u.messages_received.filter(~Q(response__id__gt=0))
👤Adam
- [Django]-Prevent emails from Python from being flagged as spam
- [Django]-Django-mptt filter without breaking the tree
- [Django]-Filter on ManyToManyField intermediate table fields
- [Django]-Serve static files with Django both from CDN and local directories
- [Django]-Run a Django project from VSCODE
Source:stackexchange.com