Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda