37 lines
1 KiB
Python
37 lines
1 KiB
Python
from django import forms
|
|
from fiches.models import Profile, Department
|
|
|
|
|
|
class ProfileForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Profile
|
|
fields = [
|
|
"full_name",
|
|
"nickname",
|
|
"pronoun",
|
|
"picture",
|
|
"department",
|
|
"promotion",
|
|
"birth_date",
|
|
"thurne",
|
|
"text_field",
|
|
"printing",
|
|
"keep_me",
|
|
]
|
|
|
|
|
|
class SearchForm(forms.Form):
|
|
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")
|