Skip to content
Advertisement

Two dependent conditions in exclude DJANGO

I want to check whether the current user already has the same movie id in his personal list or not. If he has it then I want to exclude that movie from my trending list.

I want it to be something like this.

views.py

models.py

Advertisement

Answer

You can .exclude(…) with:

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:


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.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement