-
Notifications
You must be signed in to change notification settings - Fork 3
Feat: Accepted Tokens API Endpoint #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| import os | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| import dj_database_url | ||
|
|
||
| # Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There already is an |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should have been implemented in the |
||
| # URL Configuration | ||
| urlpatterns = [ | ||
| path( | ||
| "api/accepted-tokens/", | ||
| AcceptedTokenListView.as_view(), | ||
| name="accepted-token-list", | ||
| ), | ||
| ] | ||
|
|
||
| urlpatterns = [ | ||
| path("admin/", admin.site.urls), | ||
|
|
||
There was a problem hiding this comment.
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