Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Testnet #155

Merged
merged 3 commits into from
Jan 18, 2025
Merged
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
@@ -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
@@ -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:
@@ -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")
8 changes: 1 addition & 7 deletions lists/serializers.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ class Meta:


class ListSerializer(ModelSerializer):
registrations_count = serializers.IntegerField(required=False)
class Meta:
model = List
fields = [
@@ -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
@@ -51,7 +48,6 @@ class Meta:
model = ListRegistration
fields = [
"id",
"list",
"registrant",
"registered_by",
"status",
@@ -62,7 +58,6 @@ class Meta:
"tx_hash",
]

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

@@ -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,
}
Loading