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

Fix multiple adventures when shared with multiple users!

This commit is contained in:
Sean Morley 2024-09-27 22:16:56 -04:00
parent c1664e82bf
commit 7e110d8670

View file

@ -75,19 +75,19 @@ class AdventureViewSet(viewsets.ModelViewSet):
# if the user is not authenticated return only public adventures for retrieve action # if the user is not authenticated return only public adventures for retrieve action
if not self.request.user.is_authenticated: if not self.request.user.is_authenticated:
if self.action == 'retrieve': if self.action == 'retrieve':
return Adventure.objects.filter(is_public=True).distinct() return Adventure.objects.filter(is_public=True).distinct().order_by('-updated_at')
return Adventure.objects.none() return Adventure.objects.none()
if self.action == 'retrieve': if self.action == 'retrieve':
# For individual adventure retrieval, include public adventures # For individual adventure retrieval, include public adventures
return Adventure.objects.filter( return Adventure.objects.filter(
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user) Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
).distinct() ).distinct().order_by('-updated_at')
else: else:
# For other actions, include user's own adventures and shared adventures # For other actions, include user's own adventures and shared adventures
return Adventure.objects.filter( return Adventure.objects.filter(
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user) Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
).distinct() ).distinct().order_by('-updated_at')
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
queryset = self.get_queryset() queryset = self.get_queryset()