I have model "Education" where the user must enter the years of study at the university. So I just wanna that when the user adds the year of the beginning of studing, the year of the end of studing cannot be lower than the year of the beginning of studing and must be within +10 years from the year of the beginning of studing.
Now my models looks like that:
My models:
def current_year():
return datetime.date.today().year
def max_value_current_year(value):
return MaxValueValidator(current_year())(value)
class Education(models.Model):
name_university=models.CharField('University',max_length=300, blank=True)
degree_of_edu=models.CharField('Degree of Education', max_length=25, blank=True)
start_year=models.IntegerField('Start year',default=current_year(), validators=[MinValueValidator(1945), max_value_current_year])
end_year=models.IntegerField('End year', default=current_year()+1,validators=[MinValueValidator(1945), MaxValueValidator(2100)])
speciality=models.CharField('Speciality', default='Engineer', max_length=250, blank=True)
def __str__(self):
return '{}'.format(self.name_university)
I have understood that IntegerFields can't compere with each other, because i have gotten an error already like this:
'>' not supported between instances of 'int' and 'IntegerField'
So for example: if u choosed or wrote: 2021, u would able to choose the end of studing only 2022-2031
Or is it possible to do this at all only at the form stage?