mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-22 22:39:36 +02:00
notes beta
This commit is contained in:
parent
b8994a531f
commit
4f1ad09470
8 changed files with 172 additions and 10 deletions
|
@ -4,7 +4,7 @@ from rest_framework.decorators import action
|
|||
from rest_framework import viewsets
|
||||
from django.db.models.functions import Lower
|
||||
from rest_framework.response import Response
|
||||
from .models import Adventure, Collection, Transportation
|
||||
from .models import Adventure, Collection, Transportation, Note
|
||||
from worldtravel.models import VisitedRegion, Region, Country
|
||||
from .serializers import AdventureSerializer, CollectionSerializer, TransportationSerializer
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
@ -279,6 +279,9 @@ class CollectionViewSet(viewsets.ModelViewSet):
|
|||
# do the same for transportations
|
||||
Transportation.objects.filter(collection=instance).update(is_public=new_public_status)
|
||||
|
||||
# do the same for notes
|
||||
Note.objects.filter(collection=instance).update(is_public=new_public_status)
|
||||
|
||||
# Log the action (optional)
|
||||
action = "public" if new_public_status else "private"
|
||||
print(f"Collection {instance.id} and its adventures were set to {action}")
|
||||
|
@ -313,6 +316,10 @@ class CollectionViewSet(viewsets.ModelViewSet):
|
|||
Prefetch('transportation_set', queryset=Transportation.objects.filter(
|
||||
Q(is_public=True) | Q(user_id=self.request.user.id)
|
||||
))
|
||||
).prefetch_related(
|
||||
Prefetch('note_set', queryset=Note.objects.filter(
|
||||
Q(is_public=True) | Q(user_id=self.request.user.id)
|
||||
))
|
||||
)
|
||||
return self.apply_sorting(adventures)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue