how to user filter in manytomany django

Solutions on MaxInterview for how to user filter in manytomany django by the best coders in the world

showing results for - "how to user filter in manytomany django"
Isabel
23 Nov 2018
1users_in_1zone = User.objects.filter(zones__id=<id1>)
2# same thing but using in
3users_in_1zone = User.objects.filter(zones__in=[<id1>])
4
5# filtering on a few zones, by id
6users_in_zones = User.objects.filter(zones__in=[<id1>, <id2>, <id3>])
7# and by zone object (object gets converted to pk under the covers)
8users_in_zones = User.objects.filter(zones__in=[zone1, zone2, zone3])
9