A
A
Alexander2018-09-30 20:32:19
Django
Alexander, 2018-09-30 20:32:19

How to display months from database?

Here is a list of dates with posts
5bb107c226451072015272.png
The database has posts with publication dates, you need to group these dates into a month, year, count their number and output.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-09-30
@sergey-gornostaev

groups = Post.objects.values('pub_date__year', 'pub_date__month').annotate(count=Count('pk'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question