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

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

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