[Answer]-Django Getting unwatched items

1👍

Ref the doc. Try

Photo.objects.exclude(viewsT__user=targetUser)
👤okm

0👍

Photo.photoviewtset.all() will fetch you all PhotoViewT instances associated with that Photo.

Photo.photoviewtset.filter(user=<your_current_user) will fetch you all PhotoViewT instances associated with that Photo filtered by your current_user.

Note: You do not need the ManyToManyField in the Photo model for this

0👍

 Photo.objects.exclude(viewsT__in=PhotoViewT.objects.filter(user=request.user))

 OR

 Photo.objects.filter(~Q(viewsT__in=PhotoViewT.objects.filter(user=request.user)))

Leave a comment