annuaire-eleves/fiches/forms.py

30 lines
948 B
Python
Raw Normal View History

2020-01-15 20:58:10 +01:00
from django import forms
2020-02-08 11:02:39 +01:00
from fiches.models import Profile, Department
2020-01-15 20:58:10 +01:00
2020-01-27 19:58:25 +01:00
2020-01-15 20:58:10 +01:00
class ProfileForm(forms.ModelForm):
2020-01-27 19:58:25 +01:00
class Meta:
model = Profile
fields = [
"full_name",
"nickname",
"picture",
"department",
"promotion",
"birth_date",
"thurne",
"text_field",
"printing",
"keep_me"
]
2020-01-15 21:27:37 +01:00
class SearchForm(forms.Form):
2020-02-08 11:02:39 +01:00
name = forms.CharField(label='Nom/Surnom', max_length=1023, required=False)
year = forms.IntegerField(label='Promotion', required=False)
department = forms.ModelMultipleChoiceField(queryset=Department.objects.all(), required=False)
def clean(self):
cleaned_data = super().clean()
if (not cleaned_data['name'] and not cleaned_data['year'] and not cleaned_data['department']):
raise forms.ValidationError(('Tous les champs sont vides'), code='invalid')