When I save form with empty date
and date_added
fields in django-admin site then it saves empty values there. I want to save current time instead. Here's code:
from django.db import models
import datetime
from django.utils import timezone
# Create your models here.
class Event(models.Model):
def __str__(self):
return self.title
title = models.CharField(max_length=300)
date = models.DateField(default=datetime.date.today, blank=True, null=True)
date_added = models.DateTimeField(default=timezone.localtime, blank=True, null=True)
text = models.TextField()
class EventPhoto(models.Model):
event_id = models.ForeignKey(Event, on_delete=models.CASCADE)
photo = models.ImageField(upload_to='news/')
Why default=timezone.localtime
doesn't work?