How To Eliminate Duplicate Data Using If Condition In Django Template?
Is it okay to use if condition in template or html to eliminate duplicate data? Note: I have already distinct cores in my views but since i have 2 loops in 1 < tr > it dupli
Solution 1:
Since you're using two filterings in the same object, why not merge them in order to avoid duplication and using two for-loop in your template.
import itertools
cores = StudentsBehaviorGrades.objects.filter(Teacher=teacher) \
.filter(Students_Enrollment_Records__in=Students.values_list('id')).values('Grading_Behavior__Grading_Behavior__Name','Grading_Behavior__Grading_Behavior__GroupName').distinct('Grading_Behavior__Grading_Behavior__Name')\
.order_by('Grading_Behavior__Grading_Behavior__Name')
behaviors = StudentsBehaviorGrades.objects.filter(Teacher=teacher) \
.filter(Students_Enrollment_Records__in=Students.values_list('id')).values('Grading_Behavior__Grading_Behavior__Name','Grading_Behavior__Grading_Behavior__GroupName').distinct('Grading_Behavior__Grading_Behavior__GroupName')\
.order_by('Grading_Behavior__Grading_Behavior__GroupName')
matches = itertools.chain(cores, behaviors)
Post a Comment for "How To Eliminate Duplicate Data Using If Condition In Django Template?"