I have a login page, I need to check who is logging in, Example: if you are in charge of group A, go to the page with all the users in group A, if you are in charge of group B, to page of users in group B and so on
models.py
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
views.py
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})
Currently I have the login page that redirects to the success page if it is a user in django, I do not know how to do this filter of responsible