StudE-Backend/stude/student_status/serializers.py

16 lines
480 B
Python
Raw Normal View History

2023-06-26 22:06:05 +08:00
from rest_framework import serializers
from .models import StudentStatus
2023-06-26 22:06:05 +08:00
class StudentStatusSerializer(serializers.ModelSerializer):
class Meta:
model = StudentStatus
fields = '__all__'
read_only_fields = ('user',)
def create(self, validated_data):
user = self.context['request'].user
student_status, created = StudentStatus.objects.update_or_create(
user=user, defaults=validated_data)
return student_status