2023-06-28 00:49:11 +08:00
|
|
|
from rest_framework import serializers
|
|
|
|
from .models import Message
|
|
|
|
from accounts.models import CustomUser
|
2023-07-07 01:25:15 +08:00
|
|
|
from study_groups.models import StudyGroup
|
2023-06-28 00:49:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
class MessageSerializer(serializers.ModelSerializer):
|
|
|
|
user = serializers.SlugRelatedField(
|
2023-10-01 01:24:58 +08:00
|
|
|
queryset=CustomUser.objects.all(), slug_field='username', required=False)
|
2023-07-07 01:25:15 +08:00
|
|
|
study_group = serializers.SlugRelatedField(
|
2023-10-01 01:24:58 +08:00
|
|
|
queryset=StudyGroup.objects.all(), slug_field='name', required=False)
|
|
|
|
message_content = serializers.CharField()
|
|
|
|
timestamp = serializers.DateTimeField(format="%I:%M %p", required=False)
|
2023-06-28 00:49:11 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Message
|
|
|
|
fields = '__all__'
|
2023-10-01 01:24:58 +08:00
|
|
|
read_only_fields = ['user', 'study_group', 'timestamp']
|