Skip to content

Commit

Permalink
[ADD] Made a new route to serve alumni grouped by year (#83)
Browse files Browse the repository at this point in the history
Co-authored-by: parthahere001 <parthahere001.com>
  • Loading branch information
parthahere001 authored Nov 2, 2022
1 parent 7f1942b commit e2e970d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
router.register(r'linit', views.LinitViewSet)
router.register(r'timeline', views.TimelineViewSet)
router.register(r'alumni', views.AlumniViewSet)
router.register(r'alumni-by-year', views.AlumniByYearViewSet)
router.register(r'techbytes', views.TechBytesViewSet)
router.register(r'devposts', views.DevPostViewSet)
router.register(r'configs', views.ConfigViewSet)
Expand Down
17 changes: 13 additions & 4 deletions main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from main.models import Config, Event, Profile, Alumni, About, Project, Contact, Activity, CarouselImage, Linit, Timeline, LinitImage, TechBytes, DevPost
from main import serializers
from main.forms import ProfileForm, ProfileChangeForm, MemberRegistrationForm
from django.contrib.auth.forms import UserCreationForm
from django.http import HttpResponseRedirect, HttpResponse
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.urls import reverse, NoReverseMatch
from django.urls import reverse
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import AllowAny
from collections import defaultdict


def register(request):
Expand Down Expand Up @@ -108,7 +108,16 @@ class AlumniViewSet(viewsets.ModelViewSet):


# ViewSets define the view behavior.

class AlumniByYearViewSet(viewsets.ModelViewSet):
queryset = Alumni.objects.all().order_by('-passout_year', 'first_name')
serializer_class = serializers.AlumniSerializer
http_method_names = ['get']
def list(self,request):
data = defaultdict(list)
alumunus = self.queryset
for alumni in alumunus :
data[alumni.passout_year].append(self.serializer_class(alumni).data)
return Response(data)

class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
Expand Down

0 comments on commit e2e970d

Please sign in to comment.