How to access semester attribute in the get query
Models.py
class Semester(models.Model):
semId=models.IntegerField(unique=True)
session=models.DecimalField(max_digits=4,decimal_places=0,null=True)
def __str__(self):
return str(self.semId)
class Course(models.Model):
course=models.Manager()
semester=models.ForeignKey(Semester,on_delete=models.CASCADE,null=True)
courseName=models.CharField(max_length=100)
courseId=models.IntegerField(unique=True)
student=models.ManyToManyField(Student)
def __str__(self):
return str(self.courseName)
Views.py
def sem(request,id):
ob=Course.course.get(semester=id)
for o in ob:
print(o.semester)
return render(request,'sem.html')