-
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
1 parent
e77dd1f
commit 795f80a
Showing
8 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
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 @@ | ||
from .views import * |
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,11 @@ | ||
from rest_framework import serializers | ||
from apps.anons.models import Anons | ||
|
||
|
||
class AnonsReadUpdateSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Anons | ||
fields = ("id",) | ||
|
||
|
||
__all__ = ("AnonsReadUpdateSerializer",) |
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,20 @@ | ||
from rest_framework.generics import UpdateAPIView | ||
from rest_framework.permissions import IsAuthenticated | ||
|
||
from apps.anons.models import Anons | ||
from apps.anons.api.AnonsReadUpdate.serializers import AnonsReadUpdateSerializer | ||
|
||
|
||
class AnonsReadUpdate(UpdateAPIView): | ||
serializer_class = AnonsReadUpdateSerializer | ||
permission_classes = (IsAuthenticated,) | ||
|
||
def perform_update(self, serializer): | ||
anons = Anons.objects.get(pk=self.kwargs["pk"]) | ||
|
||
if not anons.read_by.filter(id=self.request.user.id).exists(): | ||
anons.read_by.add(self.request.user) | ||
anons.save() | ||
|
||
|
||
__all__ = ("AnonsReadUpdate",) |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .AnonsList import * | ||
from .AnonsReadUpdate import * | ||
from .AnonsDetail import * |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from django.urls import path | ||
|
||
from apps.anons.api.AnonsList.views import AnonsListView | ||
from apps.anons.api.AnonsReadUpdate.views import AnonsReadUpdate | ||
from apps.anons.api.AnonsDetail.views import AnonsDetailView | ||
|
||
urlpatterns = [ | ||
path("", AnonsListView.as_view(), name="anons-list"), | ||
path("<int:pk>/read/", AnonsReadUpdate.as_view(), name="anons-read"), | ||
path("<int:pk>/", AnonsDetailView.as_view(), name="anons-detail"), | ||
] |