Optimize method
This commit is contained in:
parent
e94787716e
commit
095e482358
|
|
@ -41,14 +41,12 @@ class EmployeeEstablishmentPositionsView(generics.GenericAPIView):
|
|||
serializer_class = serializers.EstablishmentEmployeeListSerializer
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
pk = self.kwargs.get('pk')
|
||||
employee = get_object_or_404(models.Employee, pk=pk)
|
||||
employee_pk = self.kwargs.get('pk')
|
||||
|
||||
preload_data = defaultdict(list)
|
||||
for establishment_employee in employee.establishmentemployee_set.all() \
|
||||
for establishment_employee in self.get_queryset().filter(employee__id=employee_pk).all() \
|
||||
.prefetch_related('establishment').select_related('position'):
|
||||
establishment_name = establishment_employee.establishment.name
|
||||
|
||||
preload_data[establishment_name].append(
|
||||
serializers.EstablishmentEmployeeListSerializer(establishment_employee).data
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user