I’m trying to get a set of objects in Django Minus its existence in another set of objects. I have a Message model with a thread field that designates which thread it belongs to and a MessagesRead model that stores the user and the message that he/she has seen. I’m trying to return the messages that he/she has NOT read (to alerts for new messages), i.e. those messages that are not stored as a pair in the MessagesRead table.
Something like the following:
def unread_messages(user, thread_id):
Message.objects.filter(
self not in MessagesRead.objects.filter(
message__thread_id=thread_id,
user=user,
)
)
Can I do the above somehow or is there another way?
this assumes that MessagesRead has a foreign key back to thread with
related_nameset to messagesread_set