Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

450
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda