82 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
| from rest_framework import serializers
 | |
| 
 | |
| from .models import *
 | |
| 
 | |
| from apps.system.serializers import DictSerializer, UserListSerializer
 | |
| from apps.certset.serializers import ImplementRuleSerializer
 | |
| 
 | |
| class EmployeeSerializer(serializers.ModelSerializer):
 | |
|     """
 | |
|     普通序列化
 | |
|     """
 | |
|     user = UserListSerializer(read_only=True)
 | |
|     
 | |
|     class Meta:
 | |
|         model = Employee
 | |
|         fields = '__all__'
 | |
|     
 | |
|     
 | |
| 
 | |
|     @staticmethod
 | |
|     def setup_eager_loading(queryset):
 | |
|         """ Perform necessary eager loading of data. """
 | |
|         queryset = queryset.select_related('user')
 | |
|         return queryset
 | |
| 
 | |
| 
 | |
| class QualificationSerializer(serializers.ModelSerializer):
 | |
|     """
 | |
|     普通序列化
 | |
|     """
 | |
|     cert_field_ = DictSerializer(source='cert_field', read_only=True)
 | |
|     auditor_type_ = DictSerializer(source='auditor_type', read_only=True)
 | |
|     class Meta:
 | |
|         model = Qualification
 | |
|         fields = '__all__'
 | |
|     
 | |
|     @staticmethod
 | |
|     def setup_eager_loading(queryset):
 | |
|         """ Perform necessary eager loading of data. """
 | |
|         queryset = queryset.select_related('cert_field', 'auditor_type')
 | |
|         return queryset
 | |
| 
 | |
| class AbilitySerializer(serializers.ModelSerializer):
 | |
|     """
 | |
|     普通序列化
 | |
|     """
 | |
|     cert_field_ = DictSerializer(source='cert_field', read_only=True)
 | |
|     major_ = DictSerializer(source='major', read_only=True)
 | |
|     major_rule_code = serializers.StringRelatedField(source='major_rule')
 | |
|     afrom_ = DictSerializer(source='afrom', read_only=True)
 | |
|     auditor_abilitys_ = DictSerializer(source='auditor_abilitys', read_only=True, many = True)
 | |
|     class Meta:
 | |
|         model = Ability
 | |
|         fields = '__all__'
 | |
|     
 | |
|     # def get_auditor_abilitys_(self, obj):
 | |
|     #     return obj.auditor_abilitys.order_by('sort').values_list('name', flat=True)
 | |
|     
 | |
|     @staticmethod
 | |
|     def setup_eager_loading(queryset):
 | |
|         """ Perform necessary eager loading of data. """
 | |
|         queryset = queryset.select_related('cert_field', 'major', 'afrom', 'major_rule')
 | |
|         queryset = queryset.prefetch_related('auditor_abilitys',)
 | |
|         return queryset
 | |
| 
 | |
| class EducationSerializer(serializers.ModelSerializer):
 | |
|     """
 | |
|     普通序列化
 | |
|     """
 | |
|     level_ = DictSerializer(source='level', read_only=True)
 | |
|     class Meta:
 | |
|         model = Education
 | |
|         fields = '__all__'
 | |
| 
 | |
| 
 | |
| class TrainSerializer(serializers.ModelSerializer):
 | |
|     """
 | |
|     普通序列化
 | |
|     """
 | |
|     class Meta:
 | |
|         model = Train
 | |
|         fields = '__all__' |