ipv6-dot-work/jobs/forms.py

59 lines
1.5 KiB
Python

from django import forms
from django.forms import inlineformset_factory
from dal.autocomplete import ModelSelect2Multiple
from .models import Job, Question, Application, Answer
class JobForm(forms.ModelForm):
class Meta:
model = Job
fields = ('title', 'description', 'tags')
widgets = {
'tags': ModelSelect2Multiple(url='jobs:tag-autocomplete')
}
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)