|
10 | 10 | OpenApiResponse,
|
11 | 11 | extend_schema,
|
12 | 12 | )
|
| 13 | +from django.db.models import Count |
13 | 14 | from rest_framework.request import Request
|
14 | 15 | from rest_framework.response import Response
|
15 | 16 | from rest_framework.views import APIView
|
@@ -69,7 +70,7 @@ class ListsListAPI(APIView, CustomSizePageNumberPagination):
|
69 | 70 | )
|
70 | 71 | @method_decorator(cache_page(60 * 1))
|
71 | 72 | def get(self, request: Request, *args, **kwargs):
|
72 |
| - lists = List.objects.all().select_related("owner").prefetch_related("admins") |
| 73 | + lists = List.objects.all().select_related("owner").prefetch_related("admins", "upvotes").annotate(registrations_count=Count('registrations')) |
73 | 74 | account_id = request.query_params.get("account")
|
74 | 75 | if account_id:
|
75 | 76 | try:
|
@@ -176,10 +177,10 @@ class ListRegistrationsAPI(APIView, CustomSizePageNumberPagination):
|
176 | 177 | @method_decorator(cache_page(60 * 1))
|
177 | 178 | def get(self, request: Request, *args, **kwargs):
|
178 | 179 | list_id = kwargs.get("list_id")
|
179 |
| - #list_obj = List.objects.prefetch_related('registrations').get(on_chain_id=list_id) |
180 |
| - registrations = ListRegistration.objects.filter(list__on_chain_id=list_id).select_related("list__owner", "registrant", "registered_by").prefetch_related("list__admins") |
| 180 | + # list_obj = List.objects.get(on_chain_id=list_id) |
| 181 | + registrations = ListRegistration.objects.filter(list__on_chain_id=list_id).select_related("list", "list__owner", "registrant", "registered_by").prefetch_related("list__admins", "list__upvotes") |
181 | 182 |
|
182 |
| - # registrations = list_obj.registrations.select_related().all() |
| 183 | + # registrations = list_obj.registrations.select_related("list", "list__owner", "registrant", "registered_by").prefetch_related("list__admins").annotate(registrations_count=Count('list_registrations')).all() |
183 | 184 | status_param = request.query_params.get("status")
|
184 | 185 | category_param = request.query_params.get("category")
|
185 | 186 | search_param = request.query_params.get("search")
|
|
0 commit comments