[Django]-Django getting related objects in a many-to-many relationship

3👍

You can retrieve a list of A objects that are related to a specific B object:

b_object = B.objects.get(name='Bob')
A.objects.filter(bs=b_object)

If you a list of B objects

b_object_list = B.objects.filter(name__in=['Bob', 'Jim'])
A.objects.filter(bs__in=b_object_list)

Leave a comment