Skip to content
Advertisement

If a queryset value is in a list

I’m new to python but am surprised I can’t find another post with a similar question to mine. I’m trying to find a way to compare whether a queryset value is inside a list. Take this as an example:

JavaScript

Essentially a user has account_roles and I only want to print ‘authorised’ if a user with an admin or customer role is present. I can only get a comparison working for a single value, but an the entire list of values.

Example working for a single value only:

JavaScript

Can someone show me how this is done?

Advertisement

Answer

You need to find out if there exists a Group with a .name of the group that is in the list. We can filter with an __in lookup [Django-doc] and query with:

JavaScript
Advertisement