In django do models have a default timestamp field?
Automagically doesn't sound like something django would do by default. It wouldn't force you to require a timestamp.
I'd build an abstract base class and inherit all models from it if you don't want to forget about the timestamp / fieldname, etc.
class TimeStampedModel(models.Model):
created_on = models.DateTimeField(auto_now_add=True)
class Meta:
abstract = True
It doesn't seem like much to import wherever.TimeStampedModel
instead of django.db.models.Model
class MyFutureModels(TimeStampedModel):
....
No such thing by default, but adding one is super-easy. Just use the auto_now_add
parameter in the DateTimeField
class:
created = models.DateTimeField(auto_now_add=True)
You can also use auto_now
for an 'updated on' field.
Check the behavior of auto_now
here.
For auto_now_add
here.
A model with both fields will look like this:
class MyModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)