Skip to content

Commit

Permalink
Use a specific serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
vrigal committed Nov 26, 2024
1 parent 6ee8e58 commit feb6645
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions backend/code_review_backend/issues/api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from rest_framework.generics import ListAPIView

from code_review_backend.issues.models import Diff, IssueLink
from code_review_backend.issues.serializers import IssueHashSerializer
from code_review_backend.issues.serializers_v2 import IssueLinkHashSerializer


class IssueList(ListAPIView):
serializer_class = IssueHashSerializer
serializer_class = IssueLinkHashSerializer
allowed_modes = ["unresolved", "known", "closed"]

@cached_property
Expand All @@ -39,7 +39,7 @@ def distinct_issues(self, qs):
Convert a list of issue links to unique couples of (issue_id, issue_hash)
"""
attributes = ("issue_id", "issue__hash")
return qs.order_by(*attributes).values_list(*attributes).distinct()
return qs.order_by(*attributes).values(*attributes).distinct()

def get_unresolved(self):
"""
Expand Down
15 changes: 15 additions & 0 deletions backend/code_review_backend/issues/serializers_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers

from code_review_backend.issues.models import IssueLink


class IssueLinkHashSerializer(serializers.ModelSerializer):
"""Serialize an Issue hash from the IssueLink M2M"""

id = serializers.UUIDField(source="issue_id")
hash = serializers.CharField(source="issue__hash", max_length=32)

class Meta:
model = IssueLink
fields = ("id", "hash")
read_only_fields = ("id", "hash")

0 comments on commit feb6645

Please sign in to comment.