# a.查看全部學位課並打印學位課名稱以及授課老師 # degree_list = DegreeCourse.objects.all().values('name', 'teachers__name') # queryset = DegreeCourse.objects.all() # for row in queryset: # row.name,row.teachers.all() # b.查看全部學位課並打印學位課名稱以及學位課的獎學金 # c_obj=DegreeCourse.objects.all() # for i in c_obj: # print(i.name) # print(i.degreecourse_price_policy.all().values('price')) # degree_list = DegreeCourse.objects.all() # for row in degree_list: # print(row.name) # scholarships = row.scholarship_set.all() # for item in scholarships: # print('------>',item.time_percent,item.value) # c. 展現全部的專題課 # c_obj=Course.objects.filter(degree_course__isnull=True) # print(c_obj) # d. 查看id=1的學位課對應的全部模塊名稱 # a_obj=DegreeCourse.objects.filter(id=1).values('course__name') # print(a_obj) # obj = DegreeCourse.objects.get(id=1) # course_list = obj.course_set.all() # print(course_list) # # course_list = Course.objects.filter(degree_course_id=1) # print(course_list) # # e.獲取id = 1的專題課,並打印:課程名、級別(中文)、why_study、what_to_study_brief、全部recommend_courses # c_obj =Course.objects.filter(id=1) # print(c_obj.values('name')) # print(c_obj.first().get_level_display()) # print(c_obj.values('coursedetail__why_study')) # print(c_obj.values('coursedetail__what_to_study_brief')) # print(c_obj.values('coursedetail__recommend_courses')) # obj = Course.objects.get(id=1) # print(obj.name) # print(obj.brief) # print(obj.get_level_display() ) # print(obj.coursedetail.hours ) # print(obj.coursedetail.why_study ) # print(obj.coursedetail.recommend_courses.all() ) # f.獲取id = 1的專題課,並打印該課程相關的全部常見問題 # c_obj = Course.objects.filter(id=1).first() # print(c_obj.asked_question.all().values('question')) # obj = Course.objects.get(id=1) # ask_list = obj.asked_question.all() # for item in ask_list: # print(item.question,item.answer) # g.獲取id = 1的專題課,並打印該課程相關的課程大綱 # c_obj = Course.objects.filter(id=1) # print(c_obj.values('coursedetail__courseoutline__title')) # obj = Course.objects.get(id=1) # outline_list = obj.coursedetail.courseoutline_set.all() # for item in outline_list: # print(item.title,item.content) # # h.獲取id = 1的專題課,並打印該課程相關的全部章節 # c_obj = Course.objects.filter(id=1) # print(c_obj.values('coursechapters__name')) # obj = Course.objects.get(id=1) # chapter_list = obj.xxxxx.all() # 默認obj.表名_set.all() # for item in chapter_list: # print(item.name) # i.獲取id = 1的專題課,並打印該課程相關的全部課時 # 第1章·Python 介紹、基礎語法、流程控制 # 01 - 課程介紹(一) # 01 - 課程介紹(一) # 01 - 課程介紹(一) # 01 - 課程介紹(一) # 01 - 課程介紹(一) # 第1章·Python介紹、基礎語法、流程控制 # 01 - 課程介紹(一) # 01 - 課程介紹(一) # 01 - 課程介紹(一) # 01 - 課程介紹(一) # 01 - 課程介紹(一) # c_obj = Course.objects.filter(id=1) # for i in c_obj.values('coursechapters__chapter','coursechapters__name'): # print(i.get('coursechapters__chapter'),i.get('coursechapters__name')) # a_obj=CourseChapter.objects.filter(name=i.get('coursechapters__name')) # for j in a_obj.values('coursesections__name'): # print(j.get('coursesections__name')) # obj = Course.objects.get(id=1) # chapter_list = obj.xxxxx.all() # for chapter in chapter_list: # print(chapter.name,chapter.coursesections.all()) # 補充 # section_list = CourseSection.objects.filter(chapter__course_id=1).values('id','name','chapter_id','chapter__name') # for item in section_list: # print(item) """ [ {'chapter_id':1,'chapter__name':'美麗俏佳人','children':[ {'id':1, 'name':'課時1'}, {'id':1, 'name':'課時2'} ]}, {'chapter_id':2,'chapter__name':'美麗俏佳狗','children':[]} ] """ # i.獲取id = 1的專題課,並打印該課程相關的全部的價格策略 # c_obj = Course.objects.filter(id=1).first() # print(c_obj.price_policy.all())