How to get raw value of the QuerySet

Question:

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

Asked By: Gustavo Cavasotto

||

Answers:

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

Answered By: Ayman Ferki
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.