Commit bd04c9af548247ca9b5d6cbadb2cb0d3005bc650
1 parent
8e66c8186f
Exists in
master
Only retrieve lecture periods for a section if it's needed
Showing 4 changed files with 10 additions and 4 deletions Side-by-side Diff
flashcards/serializers.py
View file @
bd04c9a
... | ... | @@ -69,13 +69,16 @@ |
69 | 69 | |
70 | 70 | |
71 | 71 | class SectionSerializer(ModelSerializer): |
72 | - lectures = LecturePeriodSerializer(source='lectureperiod_set', many=True, read_only=True) | |
73 | 72 | lecture_times = CharField() |
74 | 73 | short_name = CharField() |
75 | 74 | long_name = CharField() |
76 | 75 | |
77 | 76 | class Meta: |
78 | 77 | model = Section |
78 | + | |
79 | +class DeepSectionSerializer(SectionSerializer): | |
80 | + lectures = LecturePeriodSerializer(source='lectureperiod_set', many=True, read_only=True) | |
81 | + | |
79 | 82 | |
80 | 83 | |
81 | 84 | class UserSerializer(ModelSerializer): |
flashcards/views.py
View file @
bd04c9a
... | ... | @@ -6,7 +6,7 @@ |
6 | 6 | from flashcards.models import Section, User, Flashcard, FlashcardHide, UserFlashcard |
7 | 7 | from flashcards.serializers import SectionSerializer, UserUpdateSerializer, RegistrationSerializer, UserSerializer, \ |
8 | 8 | PasswordResetSerializer, PasswordResetRequestSerializer, EmailPasswordSerializer, FlashcardSerializer, \ |
9 | - FlashcardUpdateSerializer | |
9 | + FlashcardUpdateSerializer, DeepSectionSerializer | |
10 | 10 | from rest_framework.decorators import detail_route, permission_classes, api_view, list_route |
11 | 11 | from rest_framework.generics import ListAPIView, GenericAPIView |
12 | 12 | from rest_framework.mixins import CreateModelMixin, RetrieveModelMixin |
... | ... | @@ -23,7 +23,7 @@ |
23 | 23 | |
24 | 24 | class SectionViewSet(ReadOnlyModelViewSet): |
25 | 25 | queryset = Section.objects.all() |
26 | - serializer_class = SectionSerializer | |
26 | + serializer_class = DeepSectionSerializer | |
27 | 27 | pagination_class = StandardResultsSetPagination |
28 | 28 | permission_classes = [IsAuthenticated] |
29 | 29 | |
... | ... | @@ -74,6 +74,7 @@ |
74 | 74 | description: space-separated list of terms |
75 | 75 | required: true |
76 | 76 | type: form |
77 | + response_serializer: SectionSerializer | |
77 | 78 | """ |
78 | 79 | query = request.GET.get('q', None) |
79 | 80 | if not query: return Response('[]') |
... | ... | @@ -111,7 +112,7 @@ |
111 | 112 | |
112 | 113 | |
113 | 114 | class UserSectionListView(ListAPIView): |
114 | - serializer_class = SectionSerializer | |
115 | + serializer_class = DeepSectionSerializer | |
115 | 116 | permission_classes = [IsAuthenticated] |
116 | 117 | |
117 | 118 | def get_queryset(self): |
flashy/urls.py
View file @
bd04c9a
... | ... | @@ -28,6 +28,7 @@ |
28 | 28 | |
29 | 29 | if IN_PRODUCTION: |
30 | 30 | urlpatterns += (url(r'^admin/django-ses/', include('django_ses.urls')),) |
31 | + urlpatterns += (url(r'^admin/pghero/', include('django_pghero.urls')),) | |
31 | 32 | |
32 | 33 | if DEBUG: |
33 | 34 | urlpatterns += [url(r'^app/(?P<path>.*)$', serve_with_default, |