[Answered ]-Two dependent conditions in exclude DJANGO

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 a ForeignKey field, since Django
will automatically add a "twin" field with an _id suffix. Therefore it should
be user, instead of uid.

Leave a comment