30-day post analysis from within the django model

Hello,

I want to analyze the posts shared in the last 30 days. With the filter method, I should get how many posts were shared on which day.

The sample data I want to reach is like this:

qs = [{created_at:2022-12-01, count:10},{created_at:2022-12-02, count:3},{created_at:2022-12-03, count:1}]

I found this code, but since the dates are in time data, it perceives each post data as if it was shared on a different day.

PostModel.filter(created_at__lte=datetime.datetime.today(),created_at__gt=datetime.datetime.today()-datetime.timedelta(days=30)).values('created_at').annotate(count=Count('id'))

This code gives me as a result
All values show as 1 even if more posts are shared on the same day.

<QuerySet [{'created_at': datetime.datetime(2022, 12, 1, 0, 55, 15, 812464), 'count': 1}, {'created_at': datetime.datetime(2022, 12, 1, 1, 14, 20, 935838), 'count': 1}, {'created_at': datetime.datetime(2022, 12, 1, 2, 14, 56, 201720), 'count': 1}, {'created_at': datetime.datetime(2022, 12, 1, 2, 24, 36, 903631), 'count': 1}, {'created_at': datetime.datetime(2022, 12, 1, 2, 28, 20, 399858), 'count': 1}, {'created_at': datetime.datetime(2022, 12, 1, 5, 30, 43, 476007), 'count': 1}, {'created_at': datetime.datetime(2022, 12, 1, 9, 11, 34, 177481), 'count': 1}, {'created_at': datetime.datetime(2022, 12, 1, 23, 
11, 24, 131683), 'count': 1}, {'created_at': datetime.datetime(2022, 12, 2, 7, 13, 46, 315324), 'count': 1}]>

this is how it worked.

PostModel.filter(created_at__date__lte=timezone.now(),created_at__date__gt=timezone.now() - timezone.timedelta(30)).annotate(created=TruncDate(‘created_at’)).values(‘created’).annotate(count=Count(‘created’))