0

I wanted to get last six months of employee count by checking joining_date field

class Employee(models.Model):
employee_name = models.CharField(max_length=100)
joining_Date = models.DateField(blank=False, null=False)

Example:

July : 12,
June : 10,
May : 8,
April : 16,
March : 13,
February : 10,

I got an answer for that from 0svoid, check here Its really working great! but problem is when there is no entry in particular month I want it to be 0 instead of not coming in the list.

Say for example june month not having any employee joining.

it should show like

July : 12,
June : 0,
May : 8,
April : 16,
March : 13,
February : 10,

instead of below one.

July : 12,
May : 8,
April : 16,
March : 13,
February : 10,

I want to work on many scenario(s) something like above , please suggest me any module or a way to generate reports to show in the template from the database(s)..

1 Answers1

1

If you don't have information into your database, you can not count and show it. Therefore you should create additional code:

from 'django.utils.dates import MONTHS

MONTHS_DICT = dict.fromkeys(MONTHS, 0)

# employees_per_month = answer from  0svoid

MONTHS_DICT.update(**employees_per_month)

print(MONTHS_DICT)
Maxim Danilov
  • 2,472
  • 1
  • 3
  • 8