Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

444
Visualizações
Create a list using values_list() in django

I'm trying to get the values of the objects saved in my database in a list and as integer, but the code I'm using is not working: if I try number[1:] I'm just gettin a blank variable in the html page and I keep getting errors telling me I'm still working with queryset and not list.

number = list(Week.objects.filter(user=request.user).values_list())

How Can I get a simple list using .values_list()?

EDIT: Added the model

class Week(models.Model):    
    user = models.ForeignKey(UserData, on_delete=models.CASCADE)
    file = models.OneToOneField(File, on_delete=models.CASCADE)
    monday     = models.PositiveIntegerField(null=True)
    tuesday    = models.PositiveIntegerField(null=True)
    wednesday  = models.PositiveIntegerField(null=True)
    thursday   = models.PositiveIntegerField(null=True)
    friday     = models.PositiveIntegerField(null=True)
    saturday   = models.PositiveIntegerField(null=True)
    sunday     = models.PositiveIntegerField(null=True)
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

number = list(Week.objects.values_list(
    'monday', 'tuesday', 'wednesday', 'thursay', 'friday', 'saturday', 'sunday'
).get(user=request.user, file=some_file))

I think it is better to explicitly list the fields: if later additional fields will appear in the Week module, it eventually can result in a lot of trouble to ensure that these are not in the number list.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda