class StarredCommentSerializer(serializers.ModelSerializer): comment = ListCommentSerializer(required=False) user = RetrieveUpdateDeleteUserSerializer(required=False) class Meta: model = StarredComment fields = ('id', 'comment', 'user', 'created')
class FlaggedCommentSerializer(serializers.ModelSerializer): post = RetrieveUpdateDestroyPostSerializer(required=False) user = RetrieveUpdateDeleteUserSerializer(required=False) class Meta: model = FlaggedComment fields = ('id', 'post', 'user', 'reason', 'action_taken', 'created')
class StarredPostSerializer(serializers.ModelSerializer): post = RetrieveUpdateDestroyPostSerializer(required=False, write_only=True) user = RetrieveUpdateDeleteUserSerializer(required=False) class Meta: model = StarredPost fields = ('id', 'post', 'user', 'created')
class QuestionCreateSerializer(serializers.ModelSerializer): author = serializers.SerializerMethodField() last_updated_by = RetrieveUpdateDeleteUserSerializer(required=False) class Meta: model = Question fields = ( 'id', 'title', 'author', 'body', 'followings', 'answers', 'views', 'created', 'updated', 'last_updated_by', 'slug', 'is_anonymous' ) extra_kwargs = { "author": { "required": False }, "last_updated_by": { "required": False }, } def get_author(self, obj): if obj.is_anonymous: return "Anonymous" return RetrieveUpdateDeleteUserSerializer(obj.author).data
class ReadPostsSerializer(serializers.ModelSerializer): user = RetrieveUpdateDeleteUserSerializer(read_only=True) post = RetrieveUpdateDestroyPostSerializer(read_only=True) class Meta: model = ReadPost fields = ('id', 'user', 'post', 'created') def to_representation(self, instance): return RetrieveUpdateDestroyPostSerializer(instance.post, context=self.context).data
def get_user(self, obj): return RetrieveUpdateDeleteUserSerializer(obj.user, context=self.context).data
def get_user(self, obj): if obj.is_anonymous: return "Anonymous" return RetrieveUpdateDeleteUserSerializer(obj.user, context=self.context).data
def to_representation(self, instance): return RetrieveUpdateDeleteUserSerializer(instance.user, context=self.context).data
class CreateCommentDownvoteSerializer(serializers.ModelSerializer): user = RetrieveUpdateDeleteUserSerializer(required=False) class Meta: model = CommentDownvote fields = ('id', 'comment', 'user', 'created')
def get_author(self, obj): if obj.is_anonymous: return "Anonymous" return RetrieveUpdateDeleteUserSerializer(obj.author).data