Hi Felix,

The way you create your validator instance it is passed the
value returned by `date.today()` at module initialization time.
That is when the Python process starts.

It means that if you started your development server or say
a gunicorn process on your server yesterday the max value
the value will compare against will be yesterday and not the
actual date which is what I'm assuming you're trying to do
here.

Instead of relying on MaxValueValidator I suggest you write
your own by simply defining the following function and
passing in your field validators list.

def validate_past_date(value):
    if value > datetime.date.today():
      raise ValidationError('This date can't be in the future')

Cheers,
Simon

Le mercredi 23 septembre 2015 17:06:54 UTC-4, felix a écrit :
>
>
> When today's date is entered in the form  it shows a form error saying 
> that this date (today) is in the future.
> What is wrong with the validator I'm using to allow dates until today?
>
> models.py
>
> ...
> import datetime
>
> ...
>
> class SolicitudBase(models.Model):
>     ....
>     fecha = 
> models.DateField(validators=[MaxValueValidator(datetime.date.today(), 
> message="This date can't be in the future")])
>     ....
>
>
> I'm using Mysql and the following settings in my django project related to 
> timezone are commented:
>
> #TIME_ZONE = 'EST'
> #USE_TZ = True
>
> My server (debian 7) is using US/Eastern timezone.
>
> and right now:
> root@webapp:~# date
> Wed Sep 23 17:04:36 EDT 2015
>
> Thanks in advance,
> Felix.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0112d817-7598-40c1-9fbc-4b5b1620b886%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to