0

How to insert date and time field in model.py and when submitting form both should be saved in the database django?

Its about django framework i m stuck in this date and time field.

28th Jun 2021, 6:49 PM
Kunjal
Kunjal - avatar
3 Respostas
+ 2
You can use django DateTimeField to store datetime. ``` date_time = models.DateTimeField() ``` If you want that it should auto add current date time then ``` date_time = models.DateTimeField(auto_now_add = True) ``` In above case if you want that this field should not appear in form, then don't forget to exclude this field.
29th Jun 2021, 6:19 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
0
Do you use django forms to store your data?
28th Jun 2021, 6:54 PM
Fu Foy
Fu Foy - avatar
0
In addition to my previous answer, there is one more option for date time field i.e, "auto_now", this field will automatically save current time whenever the record is changed or created. While "auto_now_add" only saves the time when the record is created. *DON'T USE BOTH OPTIONS IN SAME FIELD*
29th Jun 2021, 6:26 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar