from django import forms from fiches.models import Profile, Department, Phone, Social, Mail, Address class ProfileForm(forms.ModelForm): class Meta: model = Profile exclude = ["user"] 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") class PhoneForm(forms.BaseModelFormSet): class Meta: model = Phone exclude = [] class SocialForm(forms.ModelForm): class Meta: model = Social exclude = [] class MailForm(forms.ModelForm): class Meta: model = Mail exclude = [] class AddressForm(forms.ModelForm): class Meta: model = Address exclude = []