How would I use the context value to check if the currently logged in user has the same team and it's not null and the is_edit field is true.
{% if request.user.is_edit and team==request.user.team%}
produces
Could not parse the remainder: '==request.user.team' from 'team==request.user.team' edit.html
{% extends 'base.html' %} {% block title %}Add{% endblock %} {% block content %} <h1 class="cardHeader">Edit Page</h1> <div class="card"> <div class="container"> <h1>Edit team member</h1> <p>Edit contact info,location and role</p> </div> <form method = "POST" action="" enctype="multipart/form-data"> {% csrf_token %} {{ editProfileForm.as_p }} <input type="submit" name="editProfileForm" value="Save"> <!-- Check if the user who can delete the team member is the same team and had admin role? --> {% if request.user.is_edit and team==request.user.team%} <input type="submit" name="deleteProfileForm" value="Delete"> {% endif %} </form> </div> {% endblock %} views.py
def edit(request,user_id): context={} try: user = Profile.objects.get(id=user_id) print(user,user_id) except Exception as e: print(str(e)) return redirect('home') context['team']=user.team #Currently logged in user has to have is_edit? and be the same team #if request.user.team != user.team and request.user.is_edit: #return redirect('home') if request.method=="POST": if "editProfileForm" in request.POST: print('Editing') edit_profile_form = UserProfileForm(request.POST or None,instance=user) if edit_profile_form.is_valid(): edit_profile_form.save() print(edit_profile_form) return redirect('home') else: context['editProfileForm'] = edit_profile_form return render(request,'edit.html',context) if "deleteProfileForm" in request.POST: print('Deleting') try: user.delete() #messages.success(request, "The user is deleted") except Exception as e: #messages.error(request, "User does not exist") print(str(e)) pass return redirect('home') else: edit_profile_form = UserProfileForm(request.POST or None,instance=user) context['editProfileForm'] = edit_profile_form return render(request,'edit.html',context)
team == request.user.teamuser.teamwhereuser = Profile.objects.get(id=user_id), are you surerequest.useris an instance ofProfile?