我有像这样的数据库方案
models.py
class Employee(models.Model):
name = models.CharField(max_length=255)
class Attendance(models.Model):
date = models.DateField()
employee = models.ForeignKey(Employee, related_name='attendance')
class Salary(models.Model):
salary = models.DecimalField(max_digits=20, decimal_places=0)
employee = models.ForeignKey(Employee, related_name='salary')
我有detailview
的工资。
views.py
class Salary(DetailView):
context_object_name = 'salary_detail'
model = models.Salary
template_name = 'system/salary_detail.html'
在我的template.html
我使用salary_detail.name
来显示数据。
但是,我还需要显示用于生成attendance
salary_template.html
列表
怎么做?...
答案 0 :(得分:0)
我认为您应该在from
中设置salary
和class Employee(models.Model):
name = models.CharField(max_length=255)
class Attendance(models.Model):
date = models.DateField()
employee = models.ForeignKey(Employee, related_name='attendance')
class Salary(models.Model):
from_date = models.DateField()
to_date = models.DateField()
salary = models.DecimalField(max_digits=20, decimal_places=0)
employee = models.ForeignKey(Employee, related_name='salary')
employee.attendance.filter(date__gte=employee.salary.from_date, date__lte=employee.salary.to_date).values('dates')
日期,以便您可以跟踪哪个日期的工资,然后根据这样的内容过滤出勤率。< / p>
npm install material-ui@latest