I have a model similar to given below, in django 1.1.2:
from datetime import datetime
...
class Blah(models.Model):
...
date = models.DateField(default=datetime.today)
in admin interface, default value for date is given as datetime (yyyy-mm-dd hh:mm:ss.ms) on each new record. it complaints that the value does not match the field constaints if i forgot to correct the value by removing the hour part.
how can i fix it?
If you want a date, use datetime.date.today
instead of datetime.datetime.today
. Always import the datetime
module, not the class, so you can tell which is which.
import datetime
...
class Blah(models.Model):
...
date = models.DateField(default=datetime.date.today)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With