StudE-Backend/stude/student_status/serializers.py

15 lines
480 B
Python

from rest_framework import serializers
from .models import StudentStatus
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