1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-23 06:49:37 +02:00

activity types for autocomplete in the future

This commit is contained in:
Sean Morley 2024-07-17 19:35:02 -04:00
parent 7431d45124
commit 2b3c96bb8d
4 changed files with 72 additions and 5 deletions

View file

@ -341,4 +341,31 @@ class GenerateDescription(viewsets.ViewSet):
if extract.get('original') is None:
return Response({"error": "No image found"}, status=400)
return Response(extract["original"])
class ActivityTypesView(viewsets.ViewSet):
permission_classes = [IsAuthenticated]
@action(detail=False, methods=['get'])
def types(self, request):
"""
Retrieve a list of distinct activity types for adventures associated with the current user.
Args:
request (HttpRequest): The HTTP request object.
Returns:
Response: A response containing a list of distinct activity types.
"""
types = Adventure.objects.filter(user_id=request.user.id).values_list('activity_types', flat=True).distinct()
allTypes = []
for i in types:
if not i:
continue
for x in i:
if x and x not in allTypes:
allTypes.append(x)
return Response(allTypes)