Skip to content
Closed
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
2 changes: 2 additions & 0 deletions trajectfi/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""

import sys
import os

from django.core.asgi import get_asgi_application

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?
I don't think it is needed

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "trajectfi.settings")

application = get_asgi_application()
6 changes: 6 additions & 0 deletions trajectfi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os
from pathlib import Path


import dj_database_url

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand Down Expand Up @@ -161,3 +162,8 @@

# Custom settings
AUTH_USER_MODEL = "core.User"

INSTALLED_APPS = [
"core.tests", # Register the models path
"rest_framework",
]
Comment on lines +166 to +169
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There already is an INSTALLED_APPS variable containing all the necessary variable to run the app. This file is out of scope for your task.

34 changes: 34 additions & 0 deletions trajectfi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,40 @@

from django.contrib import admin
from django.urls import include, path
from django.db.models import Count
from rest_framework import serializers, generics
from rest_framework.response import Response
from rest_framework.views import APIView
from django.urls import path
from core.tests.models import AcceptedToken, Listing # type: ignore


# Serializer
class AcceptedTokenSerializer(serializers.ModelSerializer):
listing_count = serializers.SerializerMethodField()

class Meta:
model = AcceptedToken
fields = ["contract_address", "name", "listing_count"]

def get_listing_count(self, obj):
return obj.listing_count


# View
class AcceptedTokenListView(generics.ListAPIView):
queryset = AcceptedToken.objects.annotate(listing_count=Count("listing"))
serializer_class = AcceptedTokenSerializer


Comment on lines +28 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should have been implemented in the serializers.py and views.py files respectively.
Also the AcceptedToken model has no field called listing neither is there any field that references it that is called listing.

# URL Configuration
urlpatterns = [
path(
"api/accepted-tokens/",
AcceptedTokenListView.as_view(),
name="accepted-token-list",
),
]

urlpatterns = [
path("admin/", admin.site.urls),
Expand Down
Loading