Reputation:
I'm struggling with one case - I would like to have a field in my data time field model but without seconds etc. just YYYY-MM-DD HH:MM
.
I've been trying to do like this, but it doesn't work:
schedule_time = models.DateTimeField(format(['%Y-%m-%d %H:%M']), auto_now_add=True)
Could someone provide me a solution on any example?
I've also been looking for solutions there, but I haven't found anything that would help me.
Upvotes: 3
Views: 1831
Reputation: 2689
Set DATETIME_FORMAT
in your settings.py
as specified in Django docs.
Since you don't want seconds to be displayed, you can choose the below format and update in settings.py :
DATETIME_FORMAT = '%Y-%m-%d %H:%M'
When USE_L10N is True
, the locale-dictated format has higher precedence and will be applied instead. so you have to also do:
USE_L10N = False
Your settings.py
will look like this after making changes:
DATETIME_FORMAT = '%Y-%m-%d %H:%M'
USE_L10N = False
You can also manually change the format when saving it with help
of datetime
module.
Upvotes: 2