Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

442
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!