user3778319
user3778319

Reputation: 15

How to list all the groups that a user does not belong to in django?

I am new to django and have recently started working on it. I have made a django application and I am able to make the user log into it and display the group that he is a member of using:

request.user.groups.all()

Now, I want to display those groups, in which he is not a member, on a web page, upon his login, so that he can click on a link associated with that group and get himself registered. Please help.

Upvotes: 1

Views: 1558

Answers (1)

ambi
ambi

Reputation: 1316

Similar question: Django in / not in query So it should be like this:

Group.objects.exclude(id__in=request.user.groups.all().values_list('id', flat=True))

Upvotes: 1

Related Questions