To get the count of new employees per month you will need to annotate and use Trunc
to just get the month, see below:
from datetime import date
from dateutil.relativedelta import relativedelta
from django.db.models.functions import Trunc
six_months_ago = date.today() + relativedelta(months=-6)
employees_per_month = Employee.objects.filter(join_date__gte=six_months_ago)\
.annotate(
joining_month=Trunc('joining_date', 'month', output_field=DateField())
) \
.order_by('joining_month') \
.values('joining_month') \
.annotate(employees=Count('joining_month'))
This will give you a queryset with the following structure:
<QuerySet [{'joining_month': datetime.date(2022, 6, 1), 'employees': 2},
{'joining_month': datetime.date(2022, 7, 1), 'employees': 1}, ...
Edit
To convert the QS into a flat dict:
employee_count_dict = {}
for employee_count in employees_per_month:
employee_count_dict[val['joining_month']] = val['employees']