I have the following code to put all my users from a multichoice field into a list
USERS = []
for user in User.objects.filter(groups__name='accountexec'):
USERS.append((user.id,user))
I need to use Log.objects.filter() to get all the logs with a user= to a user in the USERS list
¶ Django allows using SQL subqueries.
Working with Filter Easily the most important method when working with Django models and the underlying QuerySets is the filter() method, which allows you to generate a QuerySet of objects that match a particular set of filtered parameters.
The filter() method is used to filter you search, and allows you to return only the rows that matches the search term.
Use the __in
lookup:
Log.objects.filter(user__in=User.objects.filter(groups__name='accountexec'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With