I need help getting the values of an object in a list view
class Compraslist(LoginRequiredMixin, ListView):
model = Solicitacao
template_name = 'compraslist.html'
def get_context_data(self, **kwargs):
context = super(Compraslist, self).get_context_data(**kwargs)
context['solicitacoes'] = Solicitacao.objects.all()
return context
This is my class of list, it lists the requests that were made what I need is that it only list the requests that have the status LiberacaoCompras = 1
class Orcamento(models.Model):
anexo_descricao = models.CharField("Descrição do Arquivo" ,max_length=100)
anexo_orcamento = models.FileField("Anexar Arquivo", upload_to='media/uploads/anexos/')
anexo_relacionamento = models.ForeignKey(Solicitacao, on_delete=models.CASCADE)
ROLE_CHOICES = (
(1, 'Sim'),
(2, 'Não')
)
liberacao_compras = models.PositiveSmallIntegerField("Aprovar Solicitação?",
choices=ROLE_CHOICES,
default = 1,
)
def __str__(self):
return self.anexo_descricao
class Meta:
verbose_name = 'Orcamento'
verbose_name_plural = 'Orcamentos'
I tried to get get_context_data
as follows
class Compraslist(LoginRequiredMixin, ListView):
model = Solicitacao
template_name = 'compraslist.html'
def get_context_data(self, **kwargs):
context = super(Compraslist, self).get_context_data(**kwargs)
context['solicitacoes'] = Solicitacao.objects.all()
context['anexo'] = Orcamento.objects.filter(anexoRelacionamento=self.kwargs['pk'])
return context
But an error was returned to me
context['anexo'] = Orcamento.objects.filter(anexoRelacionamento=self.kwargs['pk'])
KeyError: 'pk'