Home > Enterprise >  How to get raw value of the QuerySet
How to get raw value of the QuerySet

Time:11-21

I'm trying to return the raw value "Alberto Santos", but in my HTML, the function returns a array. <QuerySet [<Funcionarios: Alberto Santos>]>

My function "funcionarios_nome"

class ListaFuncionariosView(ListView):
    model = Funcionarios
    template_name = '../templates/funcionarios/lista_funcionarios.html'
    paginate_by = 10
    ordering = ['FuncionarioCartao']
    queryset = Funcionarios.objects.filter(EmpresaCodigo=1)
    
    def funcionarios_nome(self):
        funcionarios = Funcionarios.objects.filter(FuncionarioNome='Alberto Santos')
        return funcionarios

My website, returning all the array

MY HTML

 <p>{{ view.funcionarios_nome }}</p>

I Tried to use .values() function, but i'dont know how to use

CodePudding user response:

if you are passing data from views to template , it's recommend to use a context

useful links :

What is a context in Django?

If you expect a queryset to already return one row, you can use get() without any arguments to return the object for that row:

ex:

 Funcionarios.objects.filter(EmpresaCodigo=1).get()

source : https://docs.djangoproject.com/en/4.1/ref/models/querysets/#get

  • Related