#Annotate ManyToMany to Boolean
2 messages · Page 1 of 1 (latest)
I have tried something like
.annotate(is_seen=ExpressionWrapper(Q(seen_by__isnull=True), output_field=BooleanField())))
as suggested in a previous post... but I get an Incorrect syntax near the keyword 'IS' error... This is because the expression results to this SQL
[system_notifications_seen_by].[user_id] IS NULL AS
[is_seen] FROM [system_notifications]
LEFT OUTER JOIN [system_notifications_seen_by] ON ([system_notifications].[id] =[system_notifications_seen_by].[notifications_id])
It is trying to check if the user_id as a result of the join is NULL, but it can never be NULL so I suspect this is why it is throwing an error... Im not sure how to get around this