[PATCH v1 1/9] api: Add fields to series detail view

Adam Hassick ahassick at iol.unh.edu
Tue Jun 18 08:18:47 AEST 2024


Adds the "dependencies" and "dependents" fields to the series detail
view.

Signed-off-by: Adam Hassick <ahassick at iol.unh.edu>
---
 patchwork/api/series.py | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/patchwork/api/series.py b/patchwork/api/series.py
index b88ed1f..2b23e48 100644
--- a/patchwork/api/series.py
+++ b/patchwork/api/series.py
@@ -5,7 +5,10 @@
 
 from rest_framework.generics import ListAPIView
 from rest_framework.generics import RetrieveAPIView
-from rest_framework.serializers import SerializerMethodField
+from rest_framework.serializers import (
+    SerializerMethodField,
+    HyperlinkedRelatedField,
+)
 
 from patchwork.api.base import BaseHyperlinkedModelSerializer
 from patchwork.api.base import PatchworkPermission
@@ -24,6 +27,12 @@ class SeriesSerializer(BaseHyperlinkedModelSerializer):
     mbox = SerializerMethodField()
     cover_letter = CoverSerializer(read_only=True)
     patches = PatchSerializer(read_only=True, many=True)
+    dependencies = HyperlinkedRelatedField(
+        read_only=True, view_name='api-series-detail', many=True
+    )
+    dependents = HyperlinkedRelatedField(
+        read_only=True, view_name='api-series-detail', many=True
+    )
 
     def get_web_url(self, instance):
         request = self.context.get('request')
@@ -50,6 +59,8 @@ class SeriesSerializer(BaseHyperlinkedModelSerializer):
             'mbox',
             'cover_letter',
             'patches',
+            'dependencies',
+            'dependents',
         )
         read_only_fields = (
             'date',
@@ -60,9 +71,15 @@ class SeriesSerializer(BaseHyperlinkedModelSerializer):
             'mbox',
             'cover_letter',
             'patches',
+            'dependencies',
+            'dependents',
         )
         versioned_fields = {
             '1.1': ('web_url',),
+            '1.4': (
+                'dependencies',
+                'dependents',
+            ),
         }
         extra_kwargs = {
             'url': {'view_name': 'api-series-detail'},
@@ -76,7 +93,12 @@ class SeriesMixin(object):
     def get_queryset(self):
         return (
             Series.objects.all()
-            .prefetch_related('patches__project', 'cover_letter__project')
+            .prefetch_related(
+                'patches__project',
+                'cover_letter__project',
+                'dependencies',
+                'dependents',
+            )
             .select_related('submitter', 'project')
         )
 
-- 
2.45.2



More information about the Patchwork mailing list