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

400
Views
Django ORM extract weekday as string from queryset

What I'm trying to do is annotate a queryset with the weekday strings ("monday", "tuesday" etc).

I understand how to get the int values:

queryset = queryset.annotate(
  weekday_int=ExtractWeekDay("date"),
)

But I'm having trouble getting the string values themselves. I've tried using an ExpressionWrapper, but F objects don't seem to play well with Date objects.

I'm using postgres as my underlying database but can't find a related lookup_name for the generic Extract.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I've tested this:

import calendar


class ExtractWeekDayName(ExtractWeekDay):
    @property
    def output_field(self):
        return CharField()

    def convert_value(self, value, expression, connection, context):
        v = super(ExtractWeekDayName, self).convert_value(value, expression, connection)
        try:
            return calendar.day_name[int(v)].lower()
        except (ValueError, IndexError):
            return 'error'
        except TypeError: # NoneType
            return ''

Seems legit.

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!