19 lines
648 B
Python
19 lines
648 B
Python
from rest_framework.serializers import ModelSerializer
|
|
|
|
from .models import Equipment
|
|
from apps.system.serializers import OrganizationSimpleSerializer, UserSimpleSerializer
|
|
|
|
|
|
class EquipmentSerializer(ModelSerializer):
|
|
belong_dept_ = OrganizationSimpleSerializer(source='belong_dept', read_only=True)
|
|
keeper_ = UserSimpleSerializer(source='keeper', read_only=True)
|
|
class Meta:
|
|
model = Equipment
|
|
fields = '__all__'
|
|
|
|
@staticmethod
|
|
def setup_eager_loading(queryset):
|
|
""" Perform necessary eager loading of data. """
|
|
queryset = queryset.select_related('belong_dept','keeper')
|
|
return queryset
|