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

173
Vistas
Django group by month name

I want to get an output of {'month': 'jan', 'count': 1600} but I get the following with the current code {'month': 1, 'count': 1600}. How do I do this so I get the name of the month and not the integer.

class Month(Func):
    function = 'EXTRACT'
    template = '%(function)s(MONTH from %(expressions)s)'
    output_field = IntegerField()

Note.objects.filter(
        email_status__in=status_list,
        email_template__isnull=False,
        creation_time__gt=one_year
    ).annotate(
        month=Month('creation_time')
    ).values('month').annotate(
        total_count=Count(
            'email_id', distinct=True)
    ).values('total_count', 'month')
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You could try using DATE_FORMAT instead of EXTRACT. The following is untested.

class Month(Func):
    function = 'EXTRACT'
    template = "%(function)s(%(expressions)s, '%%b')"
    output_field = CharField()

Alternatively, it shouldn't be too tricky to convert the integers 1-12 to 'jan'-'dec' in Python.

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