Use DateTimeField
instead (see this section in the docs). Converting to datetime.datetime
is done automatically for Django.
A DateField
results in a datetime.date
and a datetime.time
object. You can use replace
to combine 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
now has 11.30. Also note that today
not changing, it just calculates the new date and time. As you can see, now you need to merge yourself, because both values โโare stored in separate fields. This is why DateTimeField
is a much better choice if you have the ability to modify model fields.
source share