This line of code is receiving an AttributeError:
now = timezone.now()
I can't figure out why. I am correctly importing the package as follows:
from django.utils import timezone
But it is still throwing:
Attribute Error: type object 'datetime.timezone' has no attribute 'now'
Model
class Donaci(models.Model):
creation_date = models.DateTimeField(auto_now_add=True, blank=True)
message = models.CharField(max_length=300, null=True, blank=True)
def whenpublished(self):
now = timezone.now()
diff = now - self.creation_date
if diff.days == 0 and diff.seconds >= 0 and diff.seconds < 60:
seconds= diff.seconds
if seconds == 1:
return str(seconds) + "second ago"
else:
return str(seconds) + " seconds ago"
Imports
from django.contrib.auth.models import AbstractUser
from django.contrib.auth import settings
from django.utils import timezone
from django.db import models
from datetime import *