[Answered ]-How do I optimize the following Django model queries?

2👍

You can do it in one query with a join:

Visit.objects.get(room_id=room_id, journey__user_id=user_id)

Whether that’s actually faster will depend on your database; you should profile.

Leave a comment