Answers for "how to user filter in manytomany django"

0

how to user filter in manytomany django

users_in_1zone = User.objects.filter(zones__id=<id1>)
# same thing but using in
users_in_1zone = User.objects.filter(zones__in=[<id1>])

# filtering on a few zones, by id
users_in_zones = User.objects.filter(zones__in=[<id1>, <id2>, <id3>])
# and by zone object (object gets converted to pk under the covers)
users_in_zones = User.objects.filter(zones__in=[zone1, zone2, zone3])
Posted by: Guest on May-29-2021

Code answers related to "how to user filter in manytomany django"

Python Answers by Framework

Browse Popular Code Answers by Language