65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
from django import forms
|
|
from django.forms import inlineformset_factory
|
|
from dal.autocomplete import ModelSelect2Multiple
|
|
|
|
from .models import Job, Question, Application, Answer, JobMessage
|
|
|
|
|
|
class JobForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Job
|
|
fields = ('title', 'description', 'tags')
|
|
widgets = {
|
|
'tags': ModelSelect2Multiple(url='jobs:tag-autocomplete')
|
|
}
|
|
|
|
class MessageForm(forms.ModelForm):
|
|
text = forms.CharField(label='', widget=forms.TextInput(attrs={"placeholder": "Write your message"}))
|
|
class Meta:
|
|
model = JobMessage
|
|
fields = ('text',)
|
|
|
|
|
|
class QuestionForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Question
|
|
fields = '__all__'
|
|
widgets = {
|
|
'name': forms.widgets.TextInput()
|
|
}
|
|
|
|
|
|
class ApplicationForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Application
|
|
exclude = ('job', 'applicant')
|
|
|
|
|
|
class AnswerForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Answer
|
|
fields = '__all__'
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.fields['text'].required = True
|
|
self.fields['question'].disabled = True
|
|
|
|
@classmethod
|
|
def inlineformset_factory(cls, extra=3):
|
|
return inlineformset_factory(
|
|
Application,
|
|
Answer,
|
|
form=cls,
|
|
min_num=extra,
|
|
max_num=extra,
|
|
validate_min=True,
|
|
can_delete=False,
|
|
can_order=False)
|
|
|
|
|
|
QuestionFormSet = inlineformset_factory(
|
|
Job, Question, form=QuestionForm, can_delete=False, can_order=False)
|
|
|
|
QuestionUpdateFormSet = inlineformset_factory(
|
|
Job, Question, form=QuestionForm, can_delete=True, can_order=False)
|