[FIX] BASE: Fix job role edit not working issue

This commit is contained in:
Horilla
2025-12-22 14:28:12 +05:30
parent a5c3bebfae
commit a551132b4a
2 changed files with 20 additions and 6 deletions

View File

@@ -92,6 +92,9 @@ class JobRoleFormView(HorillaFormView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
if self.form.instance.pk:
self.form.fields["job_position_id"].initial = (
self.form.instance.job_position_id
)
self.form_class.verbose_name = _("Update Job Role")
return context

View File

@@ -781,11 +781,6 @@ class JobRoleForm(ModelForm):
JobRole model's form
"""
cols = {"job_position_id": 12, "job_role": 12}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not self.instance.pk:
job_position_id = forms.ModelMultipleChoiceField(
queryset=JobPosition.objects.all(),
label="Job Position",
@@ -796,6 +791,22 @@ class JobRoleForm(ModelForm):
}
),
)
cols = {"job_position_id": 12, "job_role": 12}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.instance.pk:
job_position_id = forms.ModelChoiceField(
queryset=self.fields["job_position_id"].queryset,
label="Job Position",
widget=forms.Select(
attrs={
"class": "w-100 oh-select",
"style": "height:45px;",
}
),
)
self.fields["job_position_id"] = job_position_id
class Meta:
@@ -804,7 +815,8 @@ class JobRoleForm(ModelForm):
"""
model = JobRole
fields = ["job_role", "job_position_id"]
fields = "__all__"
exclude = ["is_active", "job_position_id", "company_id"]
def clean(self):
cleaned_data = super().clean()
@@ -822,7 +834,6 @@ class JobRoleForm(ModelForm):
raise ValidationError(
f"{job_role} already exists under this job position"
)
cleaned_data.pop("job_position_id", None)
return cleaned_data
def save(self, commit, *args, **kwargs) -> Any: