[Django]-Python – Check if user is in team or not

0👍

If you want to do that in the template, just use the teamplayer_set like this:

{% if request.user in object.teamplayer_set.all %}

0👍

You have it 1-on-1, so it should be

players = TeamPlayer.object.all()
if request.user.player in players
    # Do what you need to

or in template

{% if request.user.player in players %}

provided players is sent to the template

When it’s one-on-one, it’s always user.player to get related player and player.user for the related user.

Leave a comment