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

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

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 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