相关的字段Django Orm显示了多个无效的结果
查询
TechnicianAssignment.objects.filter(Q(slot__slot_date=curr_datetime.date())&Q(assigned_technician__attendance_Technician__attendance_status__in=['Rejected', 'Absent', 'Someone else reported', 'Present']))
模型简而言之:
**Table 1**:
class TechnicianTeam(models.Model):
id = models.AutoField(primary_key=True)
supervisor = models.ForeignKey('self', null=True, blank=True, related_name="TechnicianSupervisor", on_delete=models.DO_NOTHING)
customer_profile = models.ForeignKey('login.CustomerProfile',
related_name="technician_TeamUser", on_delete=models.DO_NOTHING)
class Meta:
db_table = "technician_team"
**Table2:**
class TechnicianAssignment(models.Model):
id = models.AutoField(primary_key=True)
slot = models.ForeignKey('technician_management.TechnicianSlot',
related_name="assignment_Slot", on_delete=models.DO_NOTHING)
assigned_technician = models.ForeignKey('technician_management.TechnicianTeam',
related_name="assignment_Technician", on_delete=models.DO_NOTHING)
class Meta:
db_table = "technician_assignment"
**Table3**
ATTENDANCE_CHOICES = [
('Rejected','Rejected'),
('Someone else reported','Someone else reported'),
('Absent','Absent'),
('Present','Present')
]
class TechnicianAttendance(models.Model):
id = models.AutoField(primary_key=True)
technician = models.ForeignKey('technician_management.TechnicianTeam',
related_name="attendance_Technician", on_delete=models.DO_NOTHING)
slot = models.ForeignKey('technician_management.TechnicianSlot',
related_name="attendance_Slot", on_delete=models.DO_NOTHING)
attendance_status = models.CharField(max_length=30, choices=ATTENDANCE_CHOICES, null=True)
class Meta:
db_table = "technician_attendance"
询问我的查询问题是什么:
我需要从TechnicianAssignment中滤除条目中的“ slot__slot_date”是当前日期和“ __attendance_technician __attendance_attendance_attendance_attendance_status_status__in” ,“其他人报告”,“存在”]
DB中只有1个条目“出席状态”,但是由于“ ____tendance_technician __attendance_statuse_status__in”,我的输出很多。
Query
TechnicianAssignment.objects.filter(Q(slot__slot_date=curr_datetime.date())&Q(assigned_technician__attendance_Technician__attendance_status__in=['Rejected', 'Absent', 'Someone else reported', 'Present']))
Models in short:
**Table 1**:
class TechnicianTeam(models.Model):
id = models.AutoField(primary_key=True)
supervisor = models.ForeignKey('self', null=True, blank=True, related_name="TechnicianSupervisor", on_delete=models.DO_NOTHING)
customer_profile = models.ForeignKey('login.CustomerProfile',
related_name="technician_TeamUser", on_delete=models.DO_NOTHING)
class Meta:
db_table = "technician_team"
**Table2:**
class TechnicianAssignment(models.Model):
id = models.AutoField(primary_key=True)
slot = models.ForeignKey('technician_management.TechnicianSlot',
related_name="assignment_Slot", on_delete=models.DO_NOTHING)
assigned_technician = models.ForeignKey('technician_management.TechnicianTeam',
related_name="assignment_Technician", on_delete=models.DO_NOTHING)
class Meta:
db_table = "technician_assignment"
**Table3**
ATTENDANCE_CHOICES = [
('Rejected','Rejected'),
('Someone else reported','Someone else reported'),
('Absent','Absent'),
('Present','Present')
]
class TechnicianAttendance(models.Model):
id = models.AutoField(primary_key=True)
technician = models.ForeignKey('technician_management.TechnicianTeam',
related_name="attendance_Technician", on_delete=models.DO_NOTHING)
slot = models.ForeignKey('technician_management.TechnicianSlot',
related_name="attendance_Slot", on_delete=models.DO_NOTHING)
attendance_status = models.CharField(max_length=30, choices=ATTENDANCE_CHOICES, null=True)
class Meta:
db_table = "technician_attendance"
Question what is wrong with my query:
I need to filter out from TechnicianAssignment where in entries were "slot__slot_date" is current date and "__attendance_Technician__attendance_status__in" = ['Rejected', 'Absent', 'Someone else reported', 'Present']
there is only 1 entry in db with attendance status 'Present' but i am getting many output because of "__attendance_Technician__attendance_status__in" this filter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论