I have a model (or actually 2 models, but the other is not that relevant)
class Foo(models.Model):
...
bar = models.ForeignKey(Bar,
...
)
you could use foo_queryset.bar_set.all()
to get all instances of your Bar
foo_queryset = Foo.objects.filter(attr=value)
referenced_bars = foo_queryset.bar_set.all()
The Django documentation has more details.
foo_queryset = Foo.objects.filter(attr=value)
referenced_bars = Bar.objects.filter(id__in=foo_queryset.values('bar_id'))
bars = Bar.objects.filter(foo_set__attr=value)