Use a DateTimeField
instead (see this section in the docs). Conversion to a datetime.datetime
is handled for you by Django automatically.
A DateField
results in a datetime.date
and a datetime.time
object. You can use replace
to merge these values into an updated date
:
>>> today = datetime.datetime.today()
>>> today
datetime.datetime(2012, 3, 31, 11, 6, 5, 182371)
>>> time = datetime.time(11, 30)
>>> today.replace(hour=time.hour, minute=time.minute)
datetime.datetime(2012, 3, 31, 11, 30, 5, 182371)
Note that the resulting date
has 11.30 as time now. Note also that today
is not modified, it simply computes a new date and time. As you can see, you now have to do the merging yourself because both values are stored in separate fields. That's why a DateTimeField
is a much better choice, if you have the ability to modify the model's fields.