@@ -12,7 +12,7 @@ class CommentSerializer(BaseRatioModelSerializer):
12
12
13
13
class Meta :
14
14
model = Comment
15
- fields = ' __all__'
15
+ fields = " __all__"
16
16
17
17
18
18
class CommentOverviewSerializer (CommentSerializer ):
@@ -23,23 +23,23 @@ class CommentOverviewSerializer(CommentSerializer):
23
23
24
24
class Meta (CommentSerializer .Meta ):
25
25
fields = (
26
- 'id' ,
27
- ' commenter' ,
28
- ' reply_to' ,
29
- ' is_op' ,
30
- ' ratio' ,
31
- ' post' ,
32
- ' created_at' ,
33
- ' content' ,
34
- ' upvotes' ,
35
- ' downvotes' ,
26
+ "id" ,
27
+ " commenter" ,
28
+ " reply_to" ,
29
+ " is_op" ,
30
+ " ratio" ,
31
+ " post" ,
32
+ " created_at" ,
33
+ " content" ,
34
+ " upvotes" ,
35
+ " downvotes" ,
36
36
)
37
37
38
38
def get_commenter (self , obj ):
39
39
return obj .commenter .username
40
40
41
41
def get_post (self , obj ):
42
- request = self .context .get (' request' )
42
+ request = self .context .get (" request" )
43
43
44
44
if post := Post .objects .filter (comments = obj ).first ():
45
45
return {
@@ -74,23 +74,25 @@ class CommentCreateSerializer(serializers.ModelSerializer):
74
74
75
75
class Meta :
76
76
model = Comment
77
- fields = (' path' , ' content' , ' post' )
78
- extra_kwargs = {' post' : {' write_only' : True }}
77
+ fields = (" path" , " content" , " post" )
78
+ extra_kwargs = {" post" : {" write_only" : True }}
79
79
80
80
def create (self , validated_data ):
81
81
data = {
82
- ' commenter' : self .context [' request' ].user_profile ,
83
- ' content' : validated_data [' content' ],
84
- ' post' : validated_data [' post' ],
82
+ " commenter" : self .context [" request" ].user_profile ,
83
+ " content" : validated_data [" content" ],
84
+ " post" : validated_data [" post" ],
85
85
}
86
86
87
- if path := validated_data .get (' path' ):
87
+ if path := validated_data .get (" path" ):
88
88
parent_instance = get_object_or_404 (Comment , path__match = path )
89
89
comment_instance : Comment = Comment .objects .create_child ( # pyright: ignore
90
90
parent = parent_instance , ** data
91
91
)
92
92
else :
93
- comment_instance : Comment = Comment .objects .create_child (** data ) # pyright: ignore
93
+ comment_instance : Comment = Comment .objects .create_child (
94
+ ** data
95
+ ) # pyright: ignore
94
96
95
- comment_instance .upvotes .add (data [' commenter' ])
97
+ comment_instance .upvotes .add (data [" commenter" ])
96
98
return comment_instance
0 commit comments