Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我得到';非类型';对象没有属性';天数';这是我代码中的错误_Python_Django_Nonetype_Traceback - Fatal编程技术网

Python 为什么我得到';非类型';对象没有属性';天数';这是我代码中的错误

Python 为什么我得到';非类型';对象没有属性';天数';这是我代码中的错误,python,django,nonetype,traceback,Python,Django,Nonetype,Traceback,我想要多天的房间服务,但是多天之后我看到这个结果,这是不合适的。请看图片,房间费用约为800000天,解决方案是什么请帮助我 class PatientDischarge(models.Model): assign_doctor = models.ForeignKey(Doctor, on_delete=models.CASCADE, null=True) appointment = models.ForeignKey(Appointment, on_delete=models.CASCADE)

我想要多天的房间服务,但是多天之后我看到这个结果,这是不合适的。请看图片,房间费用约为800000天,解决方案是什么请帮助我

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

当你从一天减去另一天,你会得到时间差,但你需要几天。修改你的天数

def days_count(self):
    return (self.release_date - self.appointment.entry_date).days if all([self.appointment, self.appointment.entry_date]) else 0


您能粘贴完整的错误日志吗?错误意味着
PatientDischarge
对象为None,您不能对非类型对象调用
PatientDischarge
方法
days\u count()。你可以从回溯中看出这是失败的。可能在视野中的某个地方。