Skip to content

Commit 1b3c532

Browse files
committedAug 19, 2024
validate comment files USER STORY: Python code quality #22
1 parent fd2fe6d commit 1b3c532

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed
 

‎comments/admin.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33

44
# manage comments in the admin panel
55
admin.site.register(Comment)
6-

‎comments/serializers.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ class CommentSerializer(serializers.ModelSerializer):
1010
"""
1111
owner = serializers.ReadOnlyField(source='owner.username')
1212
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')
1516
profile_id = serializers.ReadOnlyField(source='owner.profile.id')
1617
profile_image = serializers.ReadOnlyField(source='owner.profile.image.url')
1718
created_at = serializers.SerializerMethodField()
@@ -47,4 +48,4 @@ class CommentDetailSerializer(CommentSerializer):
4748
Serializer for the Comment model used in Detail view
4849
Task is a read only field so that we dont have to set it on each update
4950
"""
50-
task = serializers.ReadOnlyField(source='task.id')
51+
task = serializers.ReadOnlyField(source='task.id')

‎comments/urls.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from django.urls import path
22
from comments import views
33

4+
# URLs for the comment API
45
urlpatterns = [
56
path('comments/', views.CommentList.as_view()),
67
path('comments/<int:pk>/', views.CommentDetail.as_view())
7-
]
8+
]

‎comments/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class CommentList(generics.ListCreateAPIView):
2222
'task',
2323
]
2424

25-
2625
def perform_create(self, serializer):
2726
serializer.save(owner=self.request.user)
2827

28+
2929
class CommentDetail(generics.RetrieveUpdateDestroyAPIView):
3030
"""
3131
Retrieve a comment, or update or delete it by id if you own it.
3232
"""
3333
permission_classes = [IsOwnerOrReadOnly]
3434
serializer_class = CommentDetailSerializer
35-
queryset = Comment.objects.all()
35+
queryset = Comment.objects.all()

0 commit comments

Comments
 (0)