-1
I’ve been put on hold for lack of work opportunity in my region. Now I’ve been invited to participate in a project and I’ve come across a problem that for me is complicated.
I need to start a field with the group name and/or 'unit' this is the name of the field I created, to which the logged-in user belongs, I created a class to define and this 'unit' and I’m trying to rescue in my form, porblem aé que ta voltar vazio initially concei cirando a function now and finally a class. the code is now giving result that is a Quary/Property type in capsule or returns empty when I use the class, my code was like this:
I am using Python3 and Django3
py.models
class Employee(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
unidade = models.CharField(max_length=100)
def __str__(self):
return self.unidade
Forms.py
class get_origem(Employee):
def user_logado(slef):
return slef.user.is_authenticated()
def get_origem(self, user_logado):
usuario = User.objects.get(username=user_logado)
grupo_unidade = usuario.employee.unidade
if grupo_unidade == user_logado:
self.grupo_unidade
else:
self.grupo_unidade = 'NAO PERTENCE AO GRUPO'
return self.grupo_unidade
return self.grupo_unidade
class Cadastro_Unico_Add_Form(ModelForm):
def __init__(self, *args, **kwargs):
super(Cadastro_Unico_Add_Form, self).__init__(*args, **kwargs)
self.fields['hospital_de_origem'].initial = get_origem
doubt is how to make the result return the logged user group or unit.
the other way I tried was this:
@property
def user_logado():
return request.user.is_authenticated()
@user_logado.getter
def get_origem():
usuario = User.objects.get(username=user_logado)
grupo_unidade = usuario.employee.unidade
if usuario == get_origem:
grupo_unidade
else:
grupo_unidade = 'NAO PERTENCE AO GRUPO'
return grupo_unidade
That returns it to me: <property object at 0x7f2c84ddd470>
which I believe is the encapsulated result.
I forgot to mention, I did a lot of research I read in the Ango documentation, I understood that the @Property in capsule the class information, but I was not sure how to show this information.
– MARCELO PEREIRA DA SILVA