我有两个模型,它们两个都具有^.*$ -
模型的外键和一个公共日期字段User
。以下是模型定义:
schedule_date
我想使用某些过滤条件从class Schedule(models.Model):
schedule_date = models.DateField()
user = models.ForeignKey(User, related_name='schedule_set')
start_time = models.TimeField()
end_time = models.TimeField()
breaks = JSONField()
class Attendance(models.Model):
schedule_date = models.DateField()
user = models.ForeignKey(User, related_name='attendance_set')
calculated_attendance = models.DecimalField(null=False, decimal_places=2, max_digits=3)
adjusted_attendance = models.DecimalField(null=True, decimal_places=2, max_digits=3)
approved_by = models.ForeignKey(User, related_name='attendance_approved_by_set', null=True)
approved_at = models.DateTimeField(null=True)
calculation_details = JSONField()
模型中获取行,并且还想为Attendance
相同的每一行访问相应的Schedule
行。就SQL而言,我想运行以下查询:
schedule_date