How To Solve Error "'nonetype' Object Has No Attribute 'day'" In Django Application
I noticed this error in my application, ''NoneType' object has no attribute 'day''. What I have noticed about it is that. I have a model named course_schedule, the course schedule
Solution 1:
Looks like maybe sch is None.
You should always put your object get in a try...except block or you can use the inbuilt get_object_or_404
Solution 2:
Following a previous question snippet of your add_courses
model.
classadd_courses(models.Model):
Course_Name = models.CharField(max_length=200, blank=True)
Manager_Name = models.ForeignKey(Manager_login_information, on_delete=models.CASCADE, blank=True)
description = models.TextField(default='', blank=True)
syllabus = models.TextField(default='', blank=True)
student = models.ManyToManyField(add_students_by_manager, blank=True)
schedule = models.ForeignKey(course_schedule, on_delete=models.CASCADE, blank=True)
def__str__(self):
return self.Course_Name
You have the following relationship path from Assign_teacher_to_courses
to course_schedule
:
Assign_teacher_to_courses -> add_courses -> course_schedule
Therefore to get the schedule of each course
in get_course_name_th
you should change sch = course_schedule.objects.get(id=course.Course_Name.pk)
to sch = course.Course_Name.schedule
.
Post a Comment for "How To Solve Error "'nonetype' Object Has No Attribute 'day'" In Django Application"