diff --git a/application/hrm_mgnt/forms.py b/application/hrm_mgnt/forms.py index 05c9c3b..d81021f 100644 --- a/application/hrm_mgnt/forms.py +++ b/application/hrm_mgnt/forms.py @@ -1,4 +1,6 @@ from django import forms + +from common.forms import DepartmentSelectionForm from .models import * @@ -16,7 +18,7 @@ class EmployeeInformationForm(forms.ModelForm): } -class EmployeeInformationAddForm(forms.ModelForm): +class EmployeeInformationAddForm(DepartmentSelectionForm, forms.ModelForm): class Meta: model = EmployeeInformation fields = [field.name for field in EmployeeInformation._meta.fields if @@ -27,11 +29,12 @@ class EmployeeInformationAddForm(forms.ModelForm): 'regularization_date': forms.DateInput(attrs={'type': 'date'}), 'departure_date': forms.DateInput(attrs={'type': 'date'}), 'contract_end_date': forms.DateInput(attrs={'type': 'date'}), + 'resignation_date': forms.DateInput(attrs={'type': 'date'}), 'base_salary': forms.NumberInput() } -class EmployeeInformationEditForm(forms.ModelForm): +class EmployeeInformationEditForm(DepartmentSelectionForm, forms.ModelForm): class Meta: model = EmployeeInformation fields = '__all__' diff --git a/application/hrm_mgnt/views.py b/application/hrm_mgnt/views.py index ffe222d..e0239c2 100644 --- a/application/hrm_mgnt/views.py +++ b/application/hrm_mgnt/views.py @@ -11,6 +11,7 @@ from django.views.decorators.csrf import csrf_protect from application.hrm_mgnt.forms import * from application.hrm_mgnt.models import * +from application.org_mgnt.models import SecondaryDepartment from common.auth import custom_permission_required from common.utils.page_helper import paginate_query_and_assign_numbers @@ -206,6 +207,7 @@ def emp_list_modify(request): try: instance = EmployeeInformation.objects.get(employee_id=request.GET['id']) form = EmployeeInformationEditForm(instance=instance) + form.fields['secondary_department'].queryset = SecondaryDepartment.objects.filter(primary_department=instance.primary_department).order_by('secondary_department_name') except EmployeeInformation.DoesNotExist: raise Http404("对象不存在") else: diff --git a/common/forms.py b/common/forms.py index 3316c5b..5fb7de9 100644 --- a/common/forms.py +++ b/common/forms.py @@ -27,7 +27,7 @@ class DepartmentSelectionForm(forms.Form): pass elif 'instance' in kwargs and kwargs['instance']: instance = kwargs['instance'] - if isinstance(instance.primary_department, PrimaryDepartment): + if hasattr(instance, 'primary_department') and isinstance(instance.primary_department, PrimaryDepartment): self.fields['secondary_department'].queryset = instance.primary_department.secondarydepartment_set.order_by('secondary_department_name') else: try: diff --git a/templates/form_partial.html b/templates/form_partial.html index 5fa9712..b2e9611 100644 --- a/templates/form_partial.html +++ b/templates/form_partial.html @@ -104,7 +104,7 @@ \ No newline at end of file