def get(self, request, video_id): video = Video.objects.get(id=int(video_id)) #通过外键找到章节再找到视频对应的课程 course = video.lession.course course.students += 1 course.save() # 查询用户是否已经学习了该课程 user_courses = UserCourse.objects.filter(user=request.user, course=course) if not user_courses: # 如果没有学习该门课程就关联起来 user_course = UserCourse(user=request.user, course=course) user_course.save() #相关课程推荐 # 找到学习这门课的所有用户 user_courses = UserCourse.objects.filter(course=course) # 找到学习这门课的所有用户的id user_ids = [user_course.user_id for user_course in user_courses] # 通过所有用户的id,找到所有用户学习过的所有过程 all_user_courses = UserCourse.objects.filter(user_id__in=user_ids) # 取出所有课程id course_ids = [ all_user_course.course_id for all_user_course in all_user_courses ] # 通过所有课程的id,找到所有的课程,按点击量去五个 relate_courses = Course.objects.filter( id__in=course_ids).order_by("-click_nums")[:5] # 资源 all_resources = CourseResource.objects.filter(course=course) return render( request, 'course-play.html', { 'course': course, 'all_resources': all_resources, 'relate_courses': relate_courses, 'video': video, })
def get(self, request, course_id): course = Course.objects.get(id=int(course_id)) all_resources = CourseResource.objects.filter(course=course) course.students += 1 course.save() # 查询用户是否已经学习了该课程 user_courses = UserCourse.objects.filter(user=request.user, course=course) if not user_courses: # 如果没有学习该门课程就关联起来 user_course = UserCourse(user=request.user, course=course) user_course.save() # 找到学习这门课的所有用户 user_courses = UserCourse.objects.filter(course=course) # 找到学习这门课的所有用户的id user_ids = [user_course.user_id for user_course in user_courses] # 通过所有用户的id,找到所有用户学习过的所有过程 all_user_courses = UserCourse.objects.filter(user_id__in=user_ids) # 取出所有课程id course_ids = [ all_user_course.course_id for all_user_course in all_user_courses ] # 通过所有课程的id,找到所有的课程,按点击量去五个 relate_courses = Course.objects.filter( id__in=course_ids).order_by("-click_nums")[:5] # vedio = course.lesson_set.first().get_lesson_vedio().first().name # print(vedio) return render( request, "course-video.html", { "course": course, 'all_resources': all_resources, 'relate_courses': relate_courses, })
def get(self, request, course_id, *args, **kwargs): course = Course.objects.get(id=int(course_id)) course.click_nums += 1 course.save() comments = CourseComments.objects.filter( course=course).order_by('-course__coursecomments__add_time') # 查询用户是否已经关联了该课程 user_courses = UserCourse.objects.filter(user=request.user, course=course) if not user_courses: user_course = UserCourse(user=request.user, course=course) user_course.save() course.students += 1 course.save() # 学习过该课程的所有同学 user_courses = UserCourse.objects.filter(course=course) user_ids = [user_course.user.id for user_course in user_courses] all_courses = UserCourse.objects.filter( user_id__in=user_ids).order_by("-course__click_nums")[:5] # related_courses = [user_course.course for user_course in all_courses if user_course.course.id != course.id] related_courses = [] for item in all_courses: if item.course.id != course.id: related_courses.append(item.course) course_resources = CourseResource.objects.filter(course=course) return render( request, "course-comment.html", { "course": course, "course_resources": course_resources, "related_courses": related_courses, "comments": comments })
def get(self, request, course_id, *args, **kwargs): course = Course.objects.get(id=int(course_id)) course.click_nums += 1 course.save() # 关联用户与课程 user_course = UserCourse.objects.filter(user=request.user, course=course) if not user_course: user_course = UserCourse(user=request.user, course=course) user_course.save() course.students += 1 course.save() # 显示学过该课程的人还学过哪些课程 all_user_courses = UserCourse.objects.filter(course=course) # 都学这门课的用户 all_user_id = [ user_course.user.id for user_course in all_user_courses ] # 都学这门课的用户ID all_courses = UserCourse.objects.filter( user_id__in=all_user_id)[:5] # 都学这门课的用户学的别的课程 # 所有学过当前课程人学的课程,排除当前课程 related_course = [] for course1 in all_courses: if course1.course.id != course.id: related_course.append(course1.course) # 课程资源 all_resourse = CourseResource.objects.filter(course=course) return render( request, 'course-video.html', { "course": course, 'all_resourse': all_resourse, 'related_course': related_course })
def get(self, request, cou_id): course = Course.objects.get(id=int(cou_id)) if not UserCourse.objects.filter(user=request.user, course=course): course.students += 1 course.save() user_courses = UserCourse.objects.filter(user=request.user, course=course) if not user_courses: user_course = UserCourse(user=request.user, course=course) user_course.save() user_courses = UserCourse.objects.filter(course=course) users_ids = [user_course.user.id for user_course in user_courses] all_user_courses = UserCourse.objects.filter(user_id__in=users_ids) courses_ids = [ user_course.course.id for user_course in all_user_courses ] relate_courses = Course.objects.filter(id__in=courses_ids)[:5] lessons = Lesson.objects.filter(course=course) return render( request, 'course-video.html', { 'course': course, 'lessons': lessons, 'relate_courses': relate_courses, })