數我有一個簡單的模型,跟蹤請假請求:減去models.DateField獲得天
class LeaveRequest(models.Model):
employee = models.ForeignKey(UserProfile)
supervisor = models.ForeignKey(UserProfile, related_name='+', blank=False, null=False)
submit_date = models.DateField(("Date"), default=datetime.date.today)
leave_type = models.CharField(max_length=64, choices=TYPE_CHOICES)
start_date = models.DateField(("Date"))
return_date = models.DateField(("Date"))
total_days = models.IntegerField()
notes = models.TextField(max_length=1000)
def __unicode__ (self):
return u'%s %s' % (self.employee, self.submit_date)
class Admin:
pass
class Meta:
ordering = ['-submit_date']
在我需要一個函數來計算所需的天數的視圖。其次,我需要一種方法來只計算工作日,但現在我已經得到了以下內容:
def leave_screen(request, id):
records = LeaveRequest.objects.filter(employee=id)
total_days = LeaveRequest.return_date - LeaveRequest.start_date
tpl = 'vacation/leave_request.html'
return render_to_response(tpl, {'records': records })
其產生的屬性錯誤
type object 'LeaveRequest' has no attribute 'return_date
有什麼建議?
你在這個視圖中達到什麼目的?此視圖假設顯示特定的請假記錄或列出特定員工的所有請假 – Rohan