Skip to content

Commit

Permalink
[FIX] new monthly timeline api
Browse files Browse the repository at this point in the history
  • Loading branch information
Satyam0204 committed Jan 15, 2024
1 parent 0b1d424 commit 847d0c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ db.sqlite3-*
main/media/*
media/*


env
##
db.json
##
Expand Down
2 changes: 2 additions & 0 deletions main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
router.register(r'carousel', views.CarouselImageViewSet)
router.register(r'linit', views.LinitViewSet)
router.register(r'timeline', views.TimelineViewSet)
router.register(r'timeline_monthly', views.MonthlyTimelineViewSet)
router.register(r'alumni', views.AlumniViewSet)
# In the latest DRF, We need to explicitly set base_name in our viewset url if we don't have queryset defined.
router.register(r'alumni-by-year', views.AlumniByYearViewSet, basename="alumnibyyear")
Expand All @@ -36,3 +37,4 @@
path('get_count/', views.GetCount.as_view(), name="get_count"),
path('linit-pages/', views.LinitPages.as_view(), name="linit-pages"),
]

10 changes: 7 additions & 3 deletions main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,17 @@ def get(self, request, format=None):


class TimelineViewSet(viewsets.ModelViewSet):
queryset = Timeline.objects.all().order_by('-event_time')
serializer_class = serializers.TimelineSerializers
http_method_names = ['get']

class MonthlyTimelineViewSet(viewsets.ModelViewSet):
queryset = Timeline.objects.all()
serializer_class = serializers.TimelineSerializers
http_method_names = ['get']
def get_queryset(self):
queryset = super().get_queryset()
# Order by the month of the date_field
return queryset.order_by('event_time')
return queryset.order_by('-event_time')

def group_by_month_year(self, queryset):
current_year= date.today().year
Expand Down Expand Up @@ -237,4 +241,4 @@ class DevPostViewSet(viewsets.ModelViewSet):
class ConfigViewSet(viewsets.ModelViewSet):
queryset = Config.objects.all()
serializer_class = serializers.ConfigSerializers
http_method_names = ['get']
http_method_names = ['get']

0 comments on commit 847d0c9

Please sign in to comment.