In Django DRF, I am trying to work out I can return objects siblings. For instance, I have record B, can i return records A and B also?

I can then use these to cycle blog posts for example with previous and next article links.

At the moment, i am getting the current object, and then calling the database again looking for record with same parent. I am thinking there might be more efficient way.

This is how i am doing it currently, with an action. I give the service\_id of current object, that in turn finds the service siblings via parent\_id, and the lower id. If one exists, it returns it. If not, then i get null. So essentially it would remove the need to call this action:

```
@action(
        detail=False,
        methods=["get"],
        url_path=r"get-prev-service/(?P<service_id>[\w]{0,50})",
    )
    def get_prev_service(self, request, service_id=None):
        current_service = self.queryset.get(pk=service_id)
        queryset = (
            self.queryset.filter(
                parent=current_service.parent, id__lt=current_service.id
            )
            .exclude(pk=current_service.id)
            .order_by("-id")
            .first()
        )
        serializer = self.get_serializer(queryset, many=False)

        if queryset:
            return Response(serializer.data)
        else:
            return Response()

```

Or can achieve same like so:

```
@action(
        detail=False,
        methods=["get"],
        url_path=r"get-related-services/(?P<service_id>[\w]{0,50})",
    )
    def get_related_service(self, request, service_id=None):
        current_service = self.queryset.get(pk=service_id)

        queryset = (
            self.queryset.filter(
                parent=current_service.parent, id__gt=current_service.id
            )
            .exclude(pk=current_service.id)
            .order_by("-id")
            .first()
        )
        queryset2 = (
            self.queryset.filter(
                parent=current_service.parent, id__lt=current_service.id
            )
            .exclude(pk=current_service.id)
            .order_by("-id")
            .first()
        )

        serializer = self.get_serializer(queryset, many=False)
        serializer2 = self.get_serializer(queryset2, many=False)

        return Response({"prev": serializer.data, "next": serializer2.data})

```