1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-22 22:39:36 +02:00

Implement user-specific category filtering in AdventureViewSet and update AdventureCard to display category details

This commit is contained in:
Sean Morley 2024-11-16 22:31:39 -05:00
parent ae92fc2027
commit 42f07dc2fb
4 changed files with 21 additions and 6 deletions

View file

@ -109,15 +109,18 @@ class AdventureViewSet(viewsets.ModelViewSet):
# Handle case where types is all
if 'all' in types:
types = [t[0] for t in ADVENTURE_TYPES]
valid_types = [t[0] for t in ADVENTURE_TYPES]
types = [t for t in types if t in valid_types]
types = Category.objects.filter(user_id=request.user).values_list('name', flat=True)
else:
for type in types:
if not Category.objects.filter(user_id=request.user, name=type).exists():
return Response({"error": f"Category {type} does not exist"}, status=400)
if not types:
return Response({"error": "No valid types provided"}, status=400)
queryset = Adventure.objects.filter(
type__in=types,
category__in=Category.objects.filter(name__in=types, user_id=request.user),
user_id=request.user.id
)