feat: update init users
This commit is contained in:
@@ -120,6 +120,16 @@ class TeacherStudentRelationSerializer(serializers.ModelSerializer):
|
||||
model = TeacherStudentRelation
|
||||
fields = '__all__'
|
||||
|
||||
def validate(self, attrs):
|
||||
# 师生关系只能在 带教医生(doctor) 与 学生(student) 之间建立
|
||||
teacher = attrs.get('teacher') or getattr(self.instance, 'teacher', None)
|
||||
student = attrs.get('student') or getattr(self.instance, 'student', None)
|
||||
if teacher is not None and teacher.role_type != 'doctor':
|
||||
raise serializers.ValidationError({'teacher': '带教方必须是带教医生(doctor)'})
|
||||
if student is not None and student.role_type != 'student':
|
||||
raise serializers.ValidationError({'student': '学生方必须是学生(student)'})
|
||||
return attrs
|
||||
|
||||
|
||||
class InstitutionSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
|
||||
Reference in New Issue
Block a user