from rest_framework.decorators import api_view from rest_framework.response import Response from rest_framework import status from core.models.download import Download from core.serializers.DownloadSerializer import DownloadSerializer @api_view(['GET']) def get_latest_downloads_by_type(request): types = Download.objects.values_list('type', flat=True).distinct() latest_items = [] for download_type in types: latest_item = ( Download.objects .filter(type=download_type) .order_by('-version') # Note: This is simple string sort .first() ) if latest_item: latest_items.append(latest_item) serializer = DownloadSerializer(latest_items, many=True) return Response(serializer.data)