Datefield fields in the Django model

Source: Internet
Author: User

Datefield¶
Class Datefield([Auto_now=false, Auto_now_add=false, **options]) ¶

This is a date represented by a datetime.date instance using Python. There are several additional setup parameters:

Datefield. Auto_now¶

each time you save an object, the field is automatically set to the current time. timestamp for the last modification. Note that it always uses the current date; It is not a default value that you can override.

Datefield. Auto_now_add¶

The current time is set automatically when the object is first created. timestamp used to create the time. It always uses the current date (the time it was created the first time?). ); It is not only a default value that you can override.

The default corresponding form control for this field is a TextInput. added a JavaScript-written calendar control to the Administrator site, and a shortcut button for "Today". contains an additional invalid_date error message key.

auto_now_add, auto_now, and default These settings are mutually exclusive. any combination between them will result in an error.

Note

In the current implementation, setting Auto_now or auto_now_add to True will allow this field to get both editable=false and blank=true These two settings.

Note

Auto_now and auto_now_add These two settings will always use the date of the default timezone (time zone) at the time the object is created or updated. If you don't want to do this, you can consider simply using your own default call or rewriting Save () to add your own time-saving mechanism to the Save () function. Instead of using Auto_now or Auto_now_add; Alternatively, use the datetimefield field class to replace the Datefield and decide how to handle the conversion from DateTime to date when the user renders the time.

Datefield fields in the Django model

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.