models.py(编辑:将日期字段添加到EmployeeConfig)
class Employee(models.Model):
employee_id = models.CharField(max_length=30,unique=True)
class EmployeeConfig(models.Model):
employee = models.ForeignKey(Employee,on_delete=models.CASCADE)
region = models.CharField(max_length=30)
config_start_dt = models.DateField(null=False)
config_end_dt = models.DateField(default=dt.datetime.strptime('31-Dec-2075',"%d-%b-%Y").date())
live = models.BooleanField() #only one config is live
class Team(models.Model):
team_name = models.CharField(max_length=10, unique=True)
employees = models.ManyToManyField(Employee)
每个员工都可以属于多个团队。我想创建带有queryset的上下文,如employee_id,team_names,区域(实时配置)。
问题:
上述结构对我的用例是否正确?
如何编写视图以显示所有员工的“ employee_id,区域,团队名称”,其相应的实时配置以及他们所属团队的列表?