Files
django/students/forms.py

20 lines
702 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django import forms
from .models import Student
class StudentForm(forms.ModelForm):
class Meta:
model = Student
fields = ('first_name', 'last_name', 'age', 'grade')
widgets = {
'first_name': forms.TextInput(attrs={'placeholder': 'مثلاً: سارا'}),
'last_name': forms.TextInput(attrs={'placeholder': 'مثلاً: احمدی'}),
'age': forms.NumberInput(attrs={'min': 5, 'max': 25, 'placeholder': 'سن'}),
}
def clean_age(self):
age = self.cleaned_data['age']
if not 5 <= age <= 25:
raise forms.ValidationError('سن باید بین ۵ تا ۲۵ سال باشد.')
return age