File tree 4 files changed +8
-7
lines changed
4 files changed +8
-7
lines changed Original file line number Diff line number Diff line change 3
3
4
4
# manage comments in the admin panel
5
5
admin .site .register (Comment )
6
-
Original file line number Diff line number Diff line change @@ -10,8 +10,9 @@ class CommentSerializer(serializers.ModelSerializer):
10
10
"""
11
11
owner = serializers .ReadOnlyField (source = 'owner.username' )
12
12
is_owner = serializers .SerializerMethodField ()
13
- owner_firstname = serializers .ReadOnlyField (source = 'owner.profile.firstname' )
14
- owner_lastname = serializers .ReadOnlyField (source = 'owner.profile.lastname' )
13
+ owner_firstname = serializers .ReadOnlyField (
14
+ source = 'owner.profile.firstname' )
15
+ owner_lastname = serializers .ReadOnlyField (source = 'owner.profile.lastname' )
15
16
profile_id = serializers .ReadOnlyField (source = 'owner.profile.id' )
16
17
profile_image = serializers .ReadOnlyField (source = 'owner.profile.image.url' )
17
18
created_at = serializers .SerializerMethodField ()
@@ -47,4 +48,4 @@ class CommentDetailSerializer(CommentSerializer):
47
48
Serializer for the Comment model used in Detail view
48
49
Task is a read only field so that we dont have to set it on each update
49
50
"""
50
- task = serializers .ReadOnlyField (source = 'task.id' )
51
+ task = serializers .ReadOnlyField (source = 'task.id' )
Original file line number Diff line number Diff line change 1
1
from django .urls import path
2
2
from comments import views
3
3
4
+ # URLs for the comment API
4
5
urlpatterns = [
5
6
path ('comments/' , views .CommentList .as_view ()),
6
7
path ('comments/<int:pk>/' , views .CommentDetail .as_view ())
7
- ]
8
+ ]
Original file line number Diff line number Diff line change @@ -22,14 +22,14 @@ class CommentList(generics.ListCreateAPIView):
22
22
'task' ,
23
23
]
24
24
25
-
26
25
def perform_create (self , serializer ):
27
26
serializer .save (owner = self .request .user )
28
27
28
+
29
29
class CommentDetail (generics .RetrieveUpdateDestroyAPIView ):
30
30
"""
31
31
Retrieve a comment, or update or delete it by id if you own it.
32
32
"""
33
33
permission_classes = [IsOwnerOrReadOnly ]
34
34
serializer_class = CommentDetailSerializer
35
- queryset = Comment .objects .all ()
35
+ queryset = Comment .objects .all ()
You can’t perform that action at this time.
0 commit comments