-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
28 lines (22 loc) · 1.23 KB
/
forms.py
File metadata and controls
28 lines (22 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from typing import Any
from django import forms
from .models import JobApplication, JobPost,Skills
class JobApplicationForm(forms.ModelForm):
skills = forms.CharField(help_text="Comma-seperated skills")
class Meta:
model = JobApplication
fields = ["user","job_post","education","city","state","country","available_to_start","resume","skills"]
widgets = {
'education':forms.Textarea(attrs={'class': 'form-control', 'placeholder': 'Your highest degree','rows':3}),
'city': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Enter your city'}),
'state': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Enter your state'}),
'country': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Enter your country'}),
}
def save(self,commit: bool = ...) -> Any:
job_application = super().save(commit=False)
skills_data = self.cleaned_data["skills"].split(",")
skills = [Skills.objects.get_or_create(name=name.strip())[0] for name in skills_data]
if commit:
job_application.save()
job_application.skills.set(skills)
return job_application