mirror of
https://github.com/Dadechin/Dashboard-XRoom.git
synced 2025-07-17 15:44:34 +00:00
25 lines
788 B
Python
25 lines
788 B
Python
|
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)
|