简体   繁体   中英

Django statement to save date and time when a button is clicked

I'm making a notes creator web application in django and I want to save the date and time when a note is created. (ie save date and time as soon as 'Submit' button is clicked.) What could be the django statement to do the same?

Inside your model class, add this:

created_at = models.DateTimeField(auto_now_add=True)

It assigns current time when object is created.

You can retrieve that data in html file by using:

{{ object.created_at }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM