1👍
✅
You can .exclude(…)
with:
trending = Movies.objects.exclude(mymovies__uid=request.user)
If you specified a related_query_name=…
[Django-doc] or a related_name=…
[Django-doc], then you need to use that to make a JOIN with your Movies
model:
trending = Movies.objects.exclude(related_name_of_fk__uid=request.user)
Note: normally a Django model is given a singular name, so
MyMovie
instead of.MyMovies
Note: Normally one does not add a suffix
_id
to aForeignKey
field, since Django
will automatically add a "twin" field with an_id
suffix. Therefore it should
beuser
, instead of.uid
Source:stackexchange.com