I have a Django model MyModel
as shown below.
It has two fields of type DateTimeField: my_field1
, my_field2
from django.db import models
from datetime import datetime
class MyModel(models.Model):
my_field1 = models.DateTimeField(default=datetime.utcnow, editable=False)
my_field2 = models.DateTimeField(
# WHAT DO I PUT HERE?
)
I want both fields to default to the value of datetime.utcnow()
. But I want to save the same value for both. It seems wasteful to call utcnow()
twice.
How can I set the default value of my_field2
so that it simply copies the default value of my_field1
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…