diff --git a/flashcards/models.py b/flashcards/models.py index f6870d2..abbaeb7 100644 --- a/flashcards/models.py +++ b/flashcards/models.py @@ -191,9 +191,17 @@ class Section(Model): class Meta: ordering = ['-course_title'] + @property + def long_name(self): + return '%s (%s)' % (self.course_title, self.instructor) + + @property + def short_name(self): + return '%s %s' % (self.department_abbreviation, self.course_num) + def __unicode__(self): return '%s %s: %s (%s %s)' % ( - self.department, self.course_num, self.course_title, self.instructor, self.quarter) + self.department_abbreviation, self.course_num, self.course_title, self.instructor, self.quarter) class LecturePeriod(Model): diff --git a/flashcards/serializers.py b/flashcards/serializers.py index 9e7e1d6..b551f31 100644 --- a/flashcards/serializers.py +++ b/flashcards/serializers.py @@ -70,6 +70,8 @@ class LecturePeriodSerializer(ModelSerializer): class SectionSerializer(ModelSerializer): lectures = LecturePeriodSerializer(source='lectureperiod_set', many=True, read_only=True) + short_name = CharField() + long_name = CharField() class Meta: model = Section diff --git a/flashcards/views.py b/flashcards/views.py index 9efb521..59065aa 100644 --- a/flashcards/views.py +++ b/flashcards/views.py @@ -77,7 +77,7 @@ class SectionViewSet(ReadOnlyModelViewSet): def search(self, request): query = request.GET.get('q',None) if not query: return Response('[]') - qs = Section.search(query.split(' '))[:5] + qs = Section.search(query.split(' '))[:20] serializer = SectionSerializer(qs, many=True) return Response(serializer.data)