I am building an online class, where students can check their result when they login to their account, I do not know how to go about querying the result from the database so as to be able to generate the result posted by the teacher for each students. Please how do I write the views.py ?
I did some things but there was an error. This is my code:
class Result(models.Model):
student = models.ForeignKey(Students, on_delete=models.CASCADE)
test = models.FloatField(null=True, blank=True)
exam = models.FloatField(null=True, blank= True)
subject = models.CharField(max_length=3, choices=SUBJECT, null=True)
class Meta:
ordering = ["-student"]
def get_total(self):
return self.exam + self.test
def __str__(self):
return self.student.first_name
class Students(models.Model):
first_name = models.CharField(max_length=15, default='top')
last_name = models.CharField(max_length=15, default='top')
phone_number = models.IntegerField(default=0)
email = models.EmailField()
class_choice = models.CharField(max_length=3, choices=CLASS)
last_accessed = models.DateTimeField(null=True, blank=True)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
class Meta:
ordering = ["last_name"]
def __str__(self):
return self.last_name
def get_absolute_url(self):
return reverse('students-detail', kwargs={'pk': self.pk})