generated from GDGVIT/template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added min year to newsletter response
- Loading branch information
Showing
2 changed files
with
22 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 19 additions & 1 deletion
20
student_welfare_backend/student_welfare_backend/customs/pagination.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
from rest_framework.pagination import PageNumberPagination | ||
|
||
from rest_framework.response import Response | ||
from student_welfare_backend.core.models import Newsletter | ||
from django.db.models import Min | ||
|
||
class CustomPagination(PageNumberPagination): | ||
page_size = 10 | ||
page_size_query_param = "size" | ||
max_page_size = 1000 | ||
|
||
class NewsletterPagination(PageNumberPagination): | ||
page_size = 10 | ||
page_size_query_param = "size" | ||
max_page_size = 1000 | ||
|
||
def get_paginated_response(self, data): | ||
min_year = Newsletter.objects.aggregate(Min('year')).get('year__min') | ||
response = super().get_paginated_response(data) | ||
return Response({ | ||
'min_year': min_year, | ||
'count': self.page.paginator.count, | ||
'next': self.get_next_link(), | ||
'previous': self.get_previous_link(), | ||
'results': data | ||
}) |