相关的字段Django Orm显示了多个无效的结果

发布于 2025-01-24 18:59:32 字数 2316 浏览 3 评论 0原文

查询

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文