[PATCH v1 1/9] api: Add fields to series detail view
Stephen Finucane
stephen at that.guru
Sat Jul 13 01:34:02 AEST 2024
On Mon, 2024-06-17 at 18:18 -0400, Adam Hassick wrote:
> Adds the "dependencies" and "dependents" fields to the series detail
> view.
>
> Signed-off-by: Adam Hassick <ahassick at iol.unh.edu>
This looks like it should be [2/N] in the series since it can't work until the
patch is merged. I also haven't assessed the performance of this yet but that's
DB-specific. From a pure API perspective though, this looks good so far.
Reviewed-by: Stephen Finucane <stephen at that.guru>
> ---
> 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')
> )
>
More information about the Patchwork
mailing list