<commit_before>from rest_framework import serializers

from students.serializers import UserInfoSerializer, ClassSerializer
from .models import News, Comment


class CommentSerializer(serializers.ModelSerializer):
    posted_by = UserInfoSerializer(read_only=True)
    author_image = serializers.SerializerMethodField()
    content = serializers.CharField(max_length=2048)


    class Meta:
        model = Comment
        fields = (
            'id', 'posted_by', 'author_image', 'content', 'posted_on', 'edited', 'last_edited_on'
        )

    def get_author_image(self, obj):
        field = None
        author = obj.posted_by

        try:
            field = author.student
        except AttributeError:
            field = author.teacher

        return field.profile_image_url

    def create(self, validated_data):
        news = self.context['news']
        request = self.context['request']

        posted_by = request.user

        return Comment.objects.create(news=news, posted_by=posted_by, **validated_data)

    def update(self, instance, validated_data):
        instance.__dict__.update(**validated_data)
        instance.save()

        return instance


class CommentReadSerializer(CommentSerializer):
    posted_by = UserInfoSerializer(read_only=True)

<commit_msg>shits<commit_after>from rest_framework import serializers

from students.serializers import UserInfoSerializer, ClassSerializer
from .models import News, Comment


class CommentSerializer(serializers.ModelSerializer):
    posted_by = UserInfoSerializer(read_only=True)
    author_image = serializers.SerializerMethodField()
    content = serializers.CharField(max_length=2048)


    class Meta:
        model = Comment
        fields = (
            'id', 'posted_by', 'author_image', 'content', 'posted_on', 'edited', 'last_edited_on'
        )

    def get_author_image(self, obj):
        field = None
        author = obj.posted_by
        
        print(author)

        try:
            field = author.student
        except AttributeError:
            field = author.teacher

        return field.profile_image_url

    def create(self, validated_data):
        news = self.context['news']
        request = self.context['request']

        posted_by = request.user

        return Comment.objects.create(news=news, posted_by=posted_by, **validated_data)

    def update(self, instance, validated_data):
        instance.__dict__.update(**validated_data)
        instance.save()

        return instance


class CommentReadSerializer(CommentSerializer):
    posted_by = UserInfoSerializer(read_only=True)


{'fraction_non_alphanumeric': 0.08682289665770265, 'fraction_numerical': 0.003073376872839032, 'mean_word_length': 3.062402496099844, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1159552', 'n_tokens_mistral': 734, 'n_tokens_neox': 686, 'n_words': 151}