nr: #1 dodano: 2017-01-02 08:01
This is a classic problem with django models/forms etc! The
datetime.datetime.now().year code inside the validator is executed only once, when the source file is read for the first time. It is not executed every time the form is submitted! So it had the value 2016 when it was first executed and still has the same value now.
To quickly see my point, restart your application server - it should be ok then (the model will be re-evaluated and will get 2017 as datetime.date.today().year!). Of course, to really fix the issue, you must change your validation logic to use a custom validator (MaxValueValidator cannot be used) that will run everytime your form is submitted.
if value < 1900 or value > datetime.datetime.now().year:
_('%(value)s is not a correcrt year!'),
# And then in your model:
year = models.PositiveSmallIntegerField(