def create(self, validated_data): parent_comment_id = validated_data['parent_comment']['id'] del validated_data['parent_comment'] post_id = validated_data['post']['id'] del validated_data['post'] comment = Comment(**validated_data) if parent_comment_id: comment.parent_comment_id = parent_comment_id if post_id: comment.post_id = post_id comment.save() return comment
def create(self, validated_data): comment = Comment(**validated_data) comment.user = User.objects.first() comment.post_id = Post.objects.first() comment.save() return comment