please visit this site for more
info
https://stackoverflow.com/questions/59764028/how-to-use-filtering-data-while-using-distinct-method-in-django
I hope my title is enough to understand what I mean, please help me on this
problem guys.
[image: data.PNG]
When I tried this:
"" id_list =
grade.objects.filter(Teacher=m.id).values_list('Students_Enrollment_Records_id',flat=True).distinct()
""
I use `distinct()` to eliminates duplicate rows of Students Enrollment
Record from the query results but I wonder why the result is like this:
[image: badresult.PNG]
What should I do to show the Students name not that QuerySet in my html?
This is my current **views.py**:
id_list =
grade.objects.filter(Teacher=m.id).values_list('Students_Enrollment_Records_id',flat=True).distinct()
print(id_list)
grades =
grade.objects.filter(Students_Enrollment_Records_id__in=id_list)
print(grades)
This is my **models.py**:
class grade(models.Model):
Teacher = models.ForeignKey(EmployeeUser, related_name='+',
on_delete=models.CASCADE,
null=True, blank=True)
Grading_Categories = models.ForeignKey(gradingCategories,
related_name='+', on_delete=models.CASCADE,
null=True, blank=True)
Subjects = models.ForeignKey(Subject, related_name='+',
on_delete=models.CASCADE, null=True)
Students_Enrollment_Records =
models.ForeignKey(StudentsEnrolledSubject, related_name='+',
on_delete=models.CASCADE, null=True)
Average = models.FloatField(null=True, blank=True)
**UPDATE**
when I tried this
piste =
grade.objects.filter(Teacher_id=m.id).values_list('Students_Enrollment_Records').annotate(Average=Avg('Average')).order_by('Grading_Categories').distinct()
the computation is fix but the teacher name, Subject and Name of students
didn't display but the ID is display just like this
[image: result.PNG]
this is my desire answer
[image: desireanswer.png]
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/fd4ff945-0793-46e7-aae4-caae652e62ed%40googlegroups.com.