Opened 13 years ago

Closed 13 years ago

#16668 closed Bug (worksforme)

Problem with was_published_today()

Reported by: dan.j.hakimi@… Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

On https://docs.djangoproject.com/en/1.3/intro/tutorial01/, you write the following function:

def was_published_today(self):
        return self.pub_date.date() == datetime.date.today()

This doesn't work (I tried it), as "today" returns a full datetime, instead of just a date (odd, I guess). Instead, you want:

def was_published_today(self):
        return self.pub_date.date() == datetime.date.today().date()

Or something else that works.

Change History (2)

comment:1 by Danny Lawrence, 13 years ago

The was_published_today should be returning a Boolean not the date.

I was unable to replicate the fault with the following commands.

 $ python manage.py shell
 >>> from polls.models import Poll,Choice
 >>> import datetime
 >>> p = Poll(question="What's up?", pub_date=datetime.datetime.now())
 >>> p.was_published_today()
 True
 >>> p.pub_date = datetime.datetime(2007, 4, 1, 0, 0)
 >>> p.was_published_today()
 False

comment:2 by Danny Lawrence, 13 years ago

Resolution: worksforme
Status: newclosed
Triage Stage: UnreviewedAccepted
Note: See TracTickets for help on using tickets.
Back to Top