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