|
10 | 10 | from django.core.exceptions import ValidationError
|
11 | 11 | from django.utils.text import slugify
|
12 | 12 | from django.utils.translation import gettext_lazy as _
|
13 |
| -from rest_framework import status |
14 | 13 | from rest_framework.exceptions import APIException
|
15 | 14 | from rest_framework.exceptions import PermissionDenied
|
16 | 15 | from rest_framework.generics import ListAPIView
|
17 | 16 | from rest_framework.generics import RetrieveUpdateAPIView
|
18 | 17 | from rest_framework.relations import RelatedField
|
19 | 18 | from rest_framework.reverse import reverse
|
20 | 19 | from rest_framework.serializers import SerializerMethodField
|
| 20 | +from rest_framework import status |
21 | 21 |
|
22 | 22 | from patchwork.api.base import BaseHyperlinkedModelSerializer
|
23 | 23 | from patchwork.api.base import PatchworkPermission
|
24 |
| -from patchwork.api.filters import PatchFilterSet |
25 |
| -from patchwork.api.embedded import PatchRelationSerializer |
| 24 | +from patchwork.api.embedded import PatchSerializer |
26 | 25 | from patchwork.api.embedded import PersonSerializer
|
27 | 26 | from patchwork.api.embedded import ProjectSerializer
|
28 | 27 | from patchwork.api.embedded import SeriesSerializer
|
29 | 28 | from patchwork.api.embedded import UserSerializer
|
| 29 | +from patchwork.api.filters import PatchFilterSet |
30 | 30 | from patchwork.models import Patch
|
31 | 31 | from patchwork.models import PatchRelation
|
32 | 32 | from patchwork.models import State
|
@@ -83,7 +83,8 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer):
|
83 | 83 | check = SerializerMethodField()
|
84 | 84 | checks = SerializerMethodField()
|
85 | 85 | tags = SerializerMethodField()
|
86 |
| - related = PatchRelationSerializer() |
| 86 | + related = PatchSerializer( |
| 87 | + source='related.patches', many=True, default=[]) |
87 | 88 |
|
88 | 89 | def get_web_url(self, instance):
|
89 | 90 | request = self.context.get('request')
|
@@ -127,14 +128,11 @@ def to_representation(self, instance):
|
127 | 128 | data = super(PatchListSerializer, self).to_representation(instance)
|
128 | 129 | data['series'] = [data['series']] if data['series'] else []
|
129 | 130 |
|
130 |
| - # stop the related serializer returning this patch in the list of |
131 |
| - # related patches. Also make it return an empty list, not null/None |
132 |
| - if 'related' in data: |
133 |
| - if data['related']: |
134 |
| - data['related'] = [p for p in data['related'] |
135 |
| - if p['id'] != instance.id] |
136 |
| - else: |
137 |
| - data['related'] = [] |
| 131 | + # Remove this patch from 'related' |
| 132 | + if 'related' in data and data['related']: |
| 133 | + data['related'] = [ |
| 134 | + x for x in data['related'] if x['id'] != data['id'] |
| 135 | + ] |
138 | 136 |
|
139 | 137 | return data
|
140 | 138 |
|
|
0 commit comments