Articles → DJANGO → auto_now and auto_now_add in Django

auto_now and auto_now_add in Django






Purpose








AttributeValueImpact
auto_nowTrueAutomatically updates the field with current date and time when data is saved.
auto_nowFalseDate and time control is displayed on the page.
auto_now_addTrueAutomatically updates the field with current date and time when data is created.
auto_now_addFalseDate 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 08, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250