feat: update init users

This commit is contained in:
2026-06-13 13:21:53 +08:00
parent 05ce7e987e
commit 46761906fe
11 changed files with 502 additions and 430 deletions
+10
View File
@@ -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: