-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django_user_pinned.views import PinnedViewMixin | ||
from rest_framework.decorators import action | ||
from rest_framework.serializers import Serializer | ||
from rest_framework.response import Response | ||
|
||
|
||
class PinAPIView(PinnedViewMixin): | ||
|
||
@action(methods=['get', 'post', 'delete'], detail=True, url_path='pin', url_name='pin', serializer_class=Serializer) | ||
def check_pin(self, request, *args, **kwargs): | ||
instance = self.get_object() | ||
method = request.method.casefold() | ||
if method == 'get': | ||
pin = instance.pinned | ||
elif method == 'post': | ||
instance.pin(self.request.user) | ||
pin = True | ||
else: | ||
instance.unpin(self.request.user) | ||
pin = False | ||
return Response({'pinned': pin}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class PinnedViewMixin: | ||
def get_queryset(self, *args, **kwargs): | ||
return super().get_queryset(*args, **kwargs).with_pinned(self.request.user) |