Articles → DJANGO → Auto_Now And Auto_Now_Add In Django
Auto_Now And Auto_Now_Add In Django
Purpose
| Attribute | Value | Impact |
|---|
| auto_now | True | Automatically updates the field with current date and time when data is saved. |
| auto_now | False | Date and time control is displayed on the page. |
| auto_now_add | True | Automatically updates the field with current date and time when data is created. |
| auto_now_add | False | Date and time control is displayed on the page. |
Example
from django.db import models
# Create your models here.
class MyNewScreen(models.Model):
name = models.CharField(max_length = 120)
created = models.DateTimeField(auto_now_add=True, null = True)
Click to Enlarge
Click to Enlarge
Click to Enlarge
| Posted By - | Karan Gupta |
| |
| Posted On - | Wednesday, January 8, 2020 |