如何解决为什么我在我的代码中得到“NoneType”对象没有属性“days_count”这个错误
我想要多个 days_count * room_service 但在多次之后我看到这个不合适的输出。请看图片,其中 Room_Cost 是 800 天,000 是什么解决方案,请帮助我..
class PatientDischarge(models.Model):
assign_doctor = models.ForeignKey(Doctor,on_delete=models.CASCADE,null=True)
appointment = models.ForeignKey(Appointment,on_delete=models.CASCADE)
release_date = models.DateField(auto_now_add=False,null=True)
medicine_cost = models.IntegerField(null=True,blank=True)
other_charge = models.IntegerField(null=True,blank=True)
def __str__(self):
return self.appointment.patient.name if all([self.appointment,self.appointment.patient,self.appointment.patient.name]) else 0
def days_count(self):
return self.release_date - self.appointment.entry_date if all([self.appointment,self.appointment.entry_date]) else 0
def room_bill(self):
return self.days_count() * self.appointment.room_service if all([self.appointment,self.appointment.room_service]) else 0
解决方法
当你从另一天中减去一天时,你会得到 timedelta,但你需要几天。修改你的天数
def days_count(self):
return (self.release_date - self.appointment.entry_date).days if all([self.appointment,self.appointment.entry_date]) else 0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。