Created
August 16, 2019 15:57
-
-
Save walison17/e12ea627dcc1516e84b08a3aef9d9d3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
courses = Course.objects.filter(published_at__lte=timezone.now()) | |
lessons_with_status = Lesson.objects.annotate( | |
is_completed=models.Case( | |
models.When( | |
models.Q(student_progress__completed_at__isnull=False) | |
& models.Q(student_progress__user=user), | |
then=models.Value(True) | |
), | |
default=models.Value(False), | |
output_field=models.BooleanField() | |
) | |
) | |
courses.filter(user_course__user=user).prefetch_related( | |
models.Prefetch('modules__lessons', queryset=lessons_with_status) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment