1
I have a login page, I need to check who’s logging in, Example: if you are responsible for group A, direct to the page with all users of group A, if you are responsible for group B, to the page of users of group B and so on
py.models
class Grupo(models.Model):
grupo = models.CharField(max_length=255)
divisao = models.ForeignKey(Divisao)
responsavel = models.ForeignKey(User)
@property
def get_responsavel(self):
return self.responsavel
def __unicode__(self):
return self.grupo
class Perfil(User):
telefone = models.CharField(max_length=255)
ramal = models.CharField(max_length=255)
data_inicio = models.DateField(default=datetime.now, blank=True)
data_fim = models.DateField(null=True, blank=True)
e_responsavel = models.BooleanField(default=False)
vinculo = models.ForeignKey(Vinculo)
grupos = models.ForeignKey(Grupo)
divisao = models.ForeignKey(Divisao)
def __unicode__(self):
return self.first_name
py views.
def login_view(request):
print(request.user.is_authenticated())
title = "Login"
form = UserLoginForm(request.POST or None)
if form.is_valid():
username = form.cleaned_data.get("username")
password = form.cleaned_data.get("password")
user = authenticate(username=username,password=password)
login(request, user)
print(request.user.is_authenticated())
return redirect("/cadastro/sucesso")
return render(request, 'sucesso.html')
return redirect("/cadastro/sucesso")
return render(request, 'login.html', {'form':form, 'title':title})
I currently have the login page that redirects to the successful page if you are a user on Jango, I don’t know how to make this responsible filter
Thanks, solved!! But answering your question, the user can be responsible for more than one group
– Bianca C.
A question, I do not want this list of users to be in the login view, I want to be in the list view, how do I compare with the logged in user like you did there?
– Bianca C.