Use the double-underscore syntax to query between relationships.
All actions for the user:
Activity.objects.filter(list__topic__user=my_user)
All actions for the user for the topic:
Activity.objects.filter(list__topic=my_topic)
(Note that currently the theme is for one user only. Not sure what this means: you are describing a user who selects a topic that cannot happen here. Potentially, the link from the topic in UserProfile should go a different way, or ManyToMany .)
source share