initial commit
This commit is contained in:
25
core/forms.py
Normal file
25
core/forms.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from django import forms
|
||||
from .models import Enregistrement
|
||||
|
||||
class EnregistrementForm(forms.ModelForm):
|
||||
est_negatif = forms.BooleanField(required=False)
|
||||
|
||||
class Meta:
|
||||
model = Enregistrement
|
||||
fields = ('montant', 'description', 'date', 'etiquette')
|
||||
widgets = {'etiquette': forms.Select(
|
||||
attrs={'class':'form-control custom-select'}
|
||||
),
|
||||
'date': forms.SelectDateWidget(
|
||||
attrs={'class':'form-control custom-select mx-1'}
|
||||
)
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
data = super().clean()
|
||||
print(data)
|
||||
# Force un nombre négatif si 'est_negatif' est coché
|
||||
if (data['est_negatif']
|
||||
and data['montant'] > 0):
|
||||
self.cleaned_data['montant'] = 0 - data['montant']
|
||||
return self.cleaned_data
|
||||
Reference in New Issue
Block a user