Menu Close

How to fix all records in database have the same value in date field with Python Django?

To fix all records in database have the same value in date field with Python Django, we set the default value to datetime.now or auto_now_add set to True.

For instance, we write

date = models.DateTimeField(auto_now_add=True, blank=True)

or

date = models.DateTimeField(default=datetime.now, blank=True)

to set the created date field to datetime.now() with

default=datetime.now

or

auto_now_add=True
Posted in Python, Python Answers