You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.7 KiB
41 lines
1.7 KiB
2 days ago
|
from rest_framework import serializers
|
||
|
from .models import Employee, WorkTimeLog, Leave, OvertimeReport, Report
|
||
|
|
||
|
# Сериализатор для модели Employee
|
||
|
class EmployeeSerializer(serializers.ModelSerializer):
|
||
|
class Meta:
|
||
|
model = Employee
|
||
|
fields = ['id', 'first_name', 'last_name', 'position', 'email', 'hired_date', 'work_schedule']
|
||
|
|
||
|
# Сериализатор для модели WorkTimeLog
|
||
|
class WorkTimeLogSerializer(serializers.ModelSerializer):
|
||
|
employee = EmployeeSerializer() # Вложенный сериализатор для сотрудника
|
||
|
|
||
|
class Meta:
|
||
|
model = WorkTimeLog
|
||
|
fields = ['id', 'employee', 'date', 'check_in', 'check_out', 'worked_hours']
|
||
|
|
||
|
# Сериализатор для модели Leave
|
||
|
class LeaveSerializer(serializers.ModelSerializer):
|
||
|
employee = EmployeeSerializer() # Вложенный сериализатор для сотрудника
|
||
|
|
||
|
class Meta:
|
||
|
model = Leave
|
||
|
fields = ['id', 'employee', 'leave_type', 'start_date', 'end_date', 'reason']
|
||
|
|
||
|
# Сериализатор для модели OvertimeReport
|
||
|
class OvertimeReportSerializer(serializers.ModelSerializer):
|
||
|
employee = EmployeeSerializer() # Вложенный сериализатор для сотрудника
|
||
|
|
||
|
class Meta:
|
||
|
model = OvertimeReport
|
||
|
fields = ['id', 'employee', 'date', 'worked_hours', 'required_hours', 'overtime', 'comment']
|
||
|
|
||
|
# Сериализатор для модели Report
|
||
|
class ReportSerializer(serializers.ModelSerializer):
|
||
|
employee = EmployeeSerializer() # Вложенный сериализатор для сотрудника
|
||
|
|
||
|
class Meta:
|
||
|
model = Report
|
||
|
fields = ['id', 'employee', 'report_date']
|