Hi everyone, I am trying to create employee of the month survey. My models are structured like this:
class Employee(models.Model):
id = models.BigIntegerField(null=False, blank=False, primary_key=True, unique=True)
employee_id = models.CharField(max_length=10, unique=True, null=True, blank=True)
department_id = models.IntegerField(null=True, blank=True)
designation_id = models.IntegerField(null=True, blank=True)
# f_name = models.CharField(max_length=40, null=True, blank=True)
# m_name = models.CharField(max_length=30, null=True, blank=True)
# l_name = models.CharField(max_length=40, null=True, blank=True)
email = models.EmailField(unique=True, null=True, blank=True)
dob = models.DateField(max_length=50, null=True, blank=True)
mobile = models.CharField(max_length=15, null=True, blank=True)
profile_picture = models.CharField(max_length=150, blank=True, null=True)
operation_id = models.IntegerField(null=True, blank=True)
status = models.BooleanField(default=True, null=True)
username = models.CharField(max_length=40, null=True, blank=True)
GENDER_CHOICES = [('m', 'Male'), ('f', 'Female'), ('other', 'Other')]
gender = models.CharField(max_length=6, choices=GENDER_CHOICES, null=True, blank=True)
name = models.CharField(max_length=100, null=True, blank=True)
signature = models.TextField(null=True, blank=True)
def save(self, *args, **kwargs):
if self.name and ' ' in self.name:
cleaned_name = ' '.join(self.name.split())
self.name = cleaned_name
super().save(*args, **kwargs)
# def save(self, *args, **kwargs):
# if self.m_name == "" or self.m_name == " " or self.m_name is None:
# self.name = f"{self.f_name} {self.l_name}"
# else:
# self.name = f"{self.f_name} {self.m_name} {self.l_name}"
#
# super().save(*args, **kwargs)
class EmployeeGroup(models.Model):
title = models.CharField(max_length=50, unique=True, blank=False, null=False)
description = models.TextField()
manager = models.ForeignKey(Employee, on_delete=models.SET_NULL, related_name='managed_groups', null=True,
blank=True)
members = models.ManyToManyField(Employee, related_name='group_members')
class EmployeeSubGroup(models.Model):
title = models.CharField(max_length=50, unique=True, blank=False, null=False)
description = models.TextField()
supervisor = models.ForeignKey(Employee, on_delete=models.SET_NULL, related_name='supervised_subgroups', null=True,
blank=True)
participants = models.ManyToManyField(Employee, related_name='employees')
group = models.ForeignKey(EmployeeGroup, related_name="subgroups", on_delete=models.CASCADE)
class Category(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class SubCategory(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name='subcategories')
name = models.CharField(max_length=100)
mark = models.IntegerField(default=1)
def __str__(self):
return self.name
class SupervisorSurvey(models.Model):
title = models.CharField(max_length=100, null=True, blank=True)
description = models.TextField(null=True, blank=True)
MONTH_CHOICES = [
(1, 'January'),
(2, 'February'),
(3, 'March'),
(4, 'April'),
(5, 'May'),
(6, 'June'),
(7, 'July'),
(8, 'August'),
(9, 'September'),
(10, 'October'),
(11, 'November'),
(12, 'December')
]
month = models.IntegerField(choices=MONTH_CHOICES, default=timezone.now().month)
year = models.IntegerField(default=timezone.now().year)
subgroup = models.ForeignKey(EmployeeSubGroup, related_name="surveys", on_delete=models.CASCADE)
deadline = models.DateField(blank=True, null=True)
categories = models.ManyToManyField(Category, related_name="surveys")
class Meta:
unique_together = [['month', 'year', 'subgroup']]
# Ensure only one survey per subgroup per month
The groups and the subgroups might change every month. How do i handle this to effectively store and retrieve past records according to month. The supervisor has to mark the participants of the subgroup according to different categories, and the manager of the group has to select an employee of the month from highest scoring nominees. I am really confused about how to go about this. I already have nested viewsets that is working but how do i handle the changing of groups and subgroups?