31、Django实战第31天:我的课程

1、编辑usercenter-mycourse.html继承usercenter-base.html

2、编辑users.views.py

...
from operation.models import UserCourse
from courses.models import Course


class MyCourseView(LoginRequiredMixin, View):
    def get(self, request):
        user_courses = UserCourse.objects.filter(user=request.user)
        course_ids = [user_course.id for user_course in user_courses]
        courses = Course.objects.filter(id__in=course_ids)
        return render(request, 'usercenter-mycourse.html', {
            'courses': courses
        })

3、编辑users.urls.py

...
from .views import  MyCourseView

urlpatterns = [
    ...
    url(r'my_course/$', MyCourseView.as_view(), name='my_course'),
]

4、编辑usercenter-base.html中的导航链接

5、编辑usercenter-mycourse.html动态数据展示

 

posted @ 2018-03-27 16:51  sellsa  阅读(223)  评论(0编辑  收藏  举报