Running Django 3.0 & Python 3.7.3

Everything works per the tutorial until I get to:

q.was_published_recently()

It throws the following error:

File 
"/Volumes/Data/DevelopmentTraining/django_tutorials/mysite/polls/models.py", 
line 19, in was_published_recently

    return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

AttributeError: type object 'datetime.datetime' has no attribute 'timedelta'

 

I also tried importing timedelta from datetime – to no avail.

 

models.py code below:

 

import datetime

from datetime import datetime, timedelta

 

from django.db import \

    models

 

from django.utils import timezone

 

# Create your models here.

 

class Question(models.Model):

    question_text = models.CharField(max_length=200)

    pub_date = models.DateTimeField('date published')

 

    def __str__(self):

        return self.question_text

 

    def was_published_recently(self):

        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

 

class Choice(models.Model):

    question = models.ForeignKey(Question, on_delete=models.CASCADE)

    choice_text = models.CharField(max_length=200)

    votes = models.IntegerField(default=0)

 

    def __str__(self):

        return self.choice_text

 

 

Much obliged,

 

Bruckner de Villiers

+27 (0)83 625 1086

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/VI1PR07MB5680C26D410997944FF9A20BC8580%40VI1PR07MB5680.eurprd07.prod.outlook.com.

Reply via email to