Verified Commit b4804658 authored by Agate's avatar Agate 💬

API to retrieve contributions

parent bc770498
......@@ -5,9 +5,18 @@ from django.contrib import admin
from django.views.generic import TemplateView
from django.views import defaults as default_views
urlpatterns = [path(settings.ADMIN_URL, admin.site.urls)] + static(
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT
)
from contributions.core import urls
urlpatterns = [
path(settings.ADMIN_URL, admin.site.urls),
path(
"api/",
include(
("contributions.core.urls", "contributions"), namespace="contributions"
),
),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if settings.DEBUG:
# This allows the error pages to be debugged during development, just visit
......
from rest_framework import serializers
from . import models
class ContributorSerizalizer(serializers.ModelSerializer):
class Meta:
model = models.Contributor
fields = ["id", "name", "username", "metadata"]
class ContributionSerializer(serializers.ModelSerializer):
contributor = ContributorSerizalizer()
class Meta:
model = models.Contribution
fields = [
"id",
"metadata",
"contributor",
"summary",
"creation_date",
"import_date",
"type",
"external_id",
"url",
]
from rest_framework import routers
from . import views
router = routers.SimpleRouter()
router.register(r"contributions", views.ContributionViewSet, "contributions")
urlpatterns = router.urls
from rest_framework import mixins, viewsets
from . import models, serializers
class ContributionViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
# filter_class = filters.TrackFavoriteFilter
serializer_class = serializers.ContributionSerializer
queryset = (
models.Contribution.objects.filter(is_visible=True)
.order_by("-creation_date")
.select_related("contributor")
)
permission_classes = []
authentication_classes = []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment