|
18 | 18 | from api.pagination import pagination_parameters
|
19 | 19 | from api.pagination import CustomSizePageNumberPagination
|
20 | 20 |
|
21 |
| -from .models import List, ListRegistrationStatus |
| 21 | +from .models import List, ListRegistration, ListRegistrationStatus |
22 | 22 | from .serializers import (
|
23 | 23 | PAGINATED_LIST_EXAMPLE,
|
24 | 24 | PAGINATED_LIST_REGISTRATION_EXAMPLE,
|
@@ -69,7 +69,7 @@ class ListsListAPI(APIView, CustomSizePageNumberPagination):
|
69 | 69 | )
|
70 | 70 | @method_decorator(cache_page(60 * 1))
|
71 | 71 | def get(self, request: Request, *args, **kwargs):
|
72 |
| - lists = List.objects.all() |
| 72 | + lists = List.objects.all().select_related("owner").prefetch_related("admins") |
73 | 73 | account_id = request.query_params.get("account")
|
74 | 74 | if account_id:
|
75 | 75 | try:
|
@@ -121,7 +121,7 @@ class ListDetailAPI(APIView):
|
121 | 121 | def get(self, request: Request, *args, **kwargs):
|
122 | 122 | list_id = kwargs.get("list_id")
|
123 | 123 | try:
|
124 |
| - list_obj = List.objects.get(on_chain_id=list_id) |
| 124 | + list_obj = List.objects.select_related("owner").prefetch_related("admins").get(on_chain_id=list_id) |
125 | 125 | except List.DoesNotExist:
|
126 | 126 | return Response(
|
127 | 127 | {"message": f"List with onchain ID {list_id} not found."}, status=404
|
@@ -176,14 +176,10 @@ class ListRegistrationsAPI(APIView, CustomSizePageNumberPagination):
|
176 | 176 | @method_decorator(cache_page(60 * 1))
|
177 | 177 | def get(self, request: Request, *args, **kwargs):
|
178 | 178 | list_id = kwargs.get("list_id")
|
179 |
| - try: |
180 |
| - list_obj = List.objects.prefetch_related('registrations').get(on_chain_id=list_id) |
181 |
| - except List.DoesNotExist: |
182 |
| - return Response( |
183 |
| - {"message": f"List with on chain ID {list_id} not found."}, status=404 |
184 |
| - ) |
| 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") |
185 | 181 |
|
186 |
| - registrations = list_obj.registrations.select_related().all() |
| 182 | + # registrations = list_obj.registrations.select_related().all() |
187 | 183 | status_param = request.query_params.get("status")
|
188 | 184 | category_param = request.query_params.get("category")
|
189 | 185 | search_param = request.query_params.get("search")
|
@@ -239,14 +235,10 @@ class ListRandomRegistrationAPI(APIView):
|
239 | 235 | )
|
240 | 236 | def get(self, request: Request, *args, **kwargs):
|
241 | 237 | list_id = kwargs.get("list_id")
|
242 |
| - try: |
243 |
| - list_obj = List.objects.get(on_chain_id=list_id) |
244 |
| - except List.DoesNotExist: |
245 |
| - return Response( |
246 |
| - {"message": f"List on chain ID {list_id} not found."}, status=404 |
247 |
| - ) |
| 238 | + # list_obj = List.objects.get(on_chain_id=list_id) |
| 239 | + registrations = ListRegistration.objects.filter(list__on_chain_id=list_id).select_related("list__owner", "registrant", "registered_by").prefetch_related("list__admins") |
248 | 240 |
|
249 |
| - registrations = list_obj.registrations.all() |
| 241 | + # registrations = list_obj.registrations.all() |
250 | 242 | status_param = request.query_params.get("status")
|
251 | 243 | if status_param:
|
252 | 244 | if status_param not in ListRegistrationStatus.values:
|
|
0 commit comments