Skip to content
Merged

Dev #156

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lists/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
OpenApiResponse,
extend_schema,
)
from django.db.models import Count
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView
Expand Down Expand Up @@ -69,7 +70,7 @@ class ListsListAPI(APIView, CustomSizePageNumberPagination):
)
@method_decorator(cache_page(60 * 1))
def get(self, request: Request, *args, **kwargs):
lists = List.objects.all().select_related("owner").prefetch_related("admins")
lists = List.objects.all().select_related("owner").prefetch_related("admins", "upvotes").annotate(registrations_count=Count('registrations'))
account_id = request.query_params.get("account")
if account_id:
try:
Expand Down Expand Up @@ -176,10 +177,10 @@ class ListRegistrationsAPI(APIView, CustomSizePageNumberPagination):
@method_decorator(cache_page(60 * 1))
def get(self, request: Request, *args, **kwargs):
list_id = kwargs.get("list_id")
#list_obj = List.objects.prefetch_related('registrations').get(on_chain_id=list_id)
registrations = ListRegistration.objects.filter(list__on_chain_id=list_id).select_related("list__owner", "registrant", "registered_by").prefetch_related("list__admins")
# list_obj = List.objects.get(on_chain_id=list_id)
registrations = ListRegistration.objects.filter(list__on_chain_id=list_id).select_related("list", "list__owner", "registrant", "registered_by").prefetch_related("list__admins", "list__upvotes")

# registrations = list_obj.registrations.select_related().all()
# registrations = list_obj.registrations.select_related("list", "list__owner", "registrant", "registered_by").prefetch_related("list__admins").annotate(registrations_count=Count('list_registrations')).all()
status_param = request.query_params.get("status")
category_param = request.query_params.get("category")
search_param = request.query_params.get("search")
Expand Down
8 changes: 1 addition & 7 deletions lists/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Meta:


class ListSerializer(ModelSerializer):
registrations_count = serializers.IntegerField(required=False)
class Meta:
model = List
fields = [
Expand All @@ -34,10 +35,6 @@ class Meta:
owner = AccountSerializer()
admins = AccountSerializer(many=True)
upvotes = ListUpvoteSerializer(many=True)
registrations_count = SerializerMethodField()

def get_registrations_count(self, obj):
return obj.registrations.count()

# def get_owner(self, obj):
# return AccountSerializer(obj.owner).data
Expand All @@ -51,7 +48,6 @@ class Meta:
model = ListRegistration
fields = [
"id",
"list",
"registrant",
"registered_by",
"status",
Expand All @@ -62,7 +58,6 @@ class Meta:
"tx_hash",
]

list = ListSerializer()
registrant = AccountSerializer()
registered_by = AccountSerializer()

Expand Down Expand Up @@ -104,7 +99,6 @@ class PaginatedListsResponseSerializer(serializers.Serializer):
"registrant_notes": "I'm excited to apply for this list",
"admin_notes": "This is a great project that I want on my list.",
"tx_hash": "EVMQsXorrrxPLHfK9UnbzFUy1SVYWvc8hwSGQZs4RbTk",
"list": SIMPLE_LIST_EXAMPLE,
"registrant": SIMPLE_ACCOUNT_EXAMPLE,
"registered_by": SIMPLE_ACCOUNT_EXAMPLE,
}
Expand Down
Loading