The doc says below in DateField.auto_now_add:
Automatically set the field to now when the object is first created. ... If you want to be able to modify this field, set the following instead of
auto_now_add=True
:
- For
DateField
:default=date.today
-from datetime.date.today()
- For
DateTimeField
:default=timezone.now
-from django.utils.timezone.now()
So to DateField() and DateTimeField(), I can set the current date and time respectively as a default value as shown below:
from datetime import date
from django.utils import timezone
class MyModel(models.Model):
date = models.DateField(default=date.today) # Here
datetime = models.DateTimeField(default=timezone.now) # Here
Now, how can I set the current time to TimeField() as a default value as shown below?
class MyModel(models.Model): # ?
time = models.TimeField(default=...)