Commit 01cad7c09527f897fb3fd5c5193db817e3041de7
1 parent
bb6c057b
Exists in
master
and in
5 other branches
added api calls and links to Subject, professors and students #267
Showing
3 changed files
with
16 additions
and
4 deletions
Show diff stats
core/urls.py
... | ... | @@ -2,14 +2,18 @@ from django.conf.urls import url, include |
2 | 2 | from django.contrib.auth import views as auth_views |
3 | 3 | from django.contrib.auth.views import password_reset, password_reset_done,password_reset_confirm, password_reset_complete |
4 | 4 | from . import views |
5 | + | |
6 | +#API IMPORTS | |
5 | 7 | from rest_framework import routers |
6 | 8 | |
7 | 9 | from users.views import UserViewSet |
10 | +from courses.views import CourseViewSet | |
8 | 11 | |
9 | 12 | #API CODE |
10 | 13 | router = routers.DefaultRouter() |
11 | 14 | router.register(r'logs', views.LogViewSet) |
12 | 15 | router.register(r'usersapi', UserViewSet) |
16 | +router.register(r'coursesapi', CourseViewSet) | |
13 | 17 | |
14 | 18 | urlpatterns = [ |
15 | 19 | url(r'^$', views.login, name='home'), | ... | ... |
courses/serializers.py
... | ... | @@ -4,12 +4,12 @@ from users.serializers import UserSerializer |
4 | 4 | |
5 | 5 | class CourseSerializer(serializers.ModelSerializer): |
6 | 6 | #The set comes from the ManyToMany Relationship in django |
7 | - students = UserSerializer(source='courses_student') | |
8 | - professors = UserSerializer(source='courses_professors') | |
7 | + #students = UserSerializer(source='students') | |
8 | + #professors = UserSerializer(source='professors') | |
9 | 9 | class Meta: |
10 | 10 | model = Course |
11 | - fields = ('name', 'slug', 'objectivies', 'content, max_students', 'create_date', | |
12 | - 'init_register_date', 'end_register_date', 'init_date', 'end_date', 'public') | |
11 | + fields = ('name', 'slug', 'objectivies', 'content', 'max_students', 'create_date', | |
12 | + 'init_register_date', 'end_register_date', 'init_date', 'end_date', 'public', 'students', 'professors') | |
13 | 13 | |
14 | 14 | class SubjectSerializer(serializers.ModelSerializer): |
15 | 15 | class Meta: | ... | ... |
courses/views.py
... | ... | @@ -26,6 +26,10 @@ from django.urls import reverse |
26 | 26 | |
27 | 27 | from datetime import date, datetime |
28 | 28 | |
29 | +#API IMPORTS | |
30 | +from rest_framework import viewsets, permissions | |
31 | +from .serializers import * | |
32 | + | |
29 | 33 | class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): |
30 | 34 | |
31 | 35 | login_url = reverse_lazy("core:home") |
... | ... | @@ -1009,3 +1013,7 @@ class FileMaterialView(LoginRequiredMixin, LogMixin, generic.DetailView): |
1009 | 1013 | |
1010 | 1014 | |
1011 | 1015 | #API VIEWS |
1016 | +class CourseViewSet(viewsets.ModelViewSet): | |
1017 | + queryset = Course.objects.all() | |
1018 | + serializer_class = CourseSerializer | |
1019 | + permissions_clas = (permissions.IsAuthenticatedOrReadOnly) | |
1012 | 1020 | \ No newline at end of file | ... | ... |