Opened 4 years ago

Closed 4 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 Changed 4 years ago by daniellawrence

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 4 years ago by daniellawrence

  • Resolution set to worksforme
  • Status changed from new to closed
  • Triage Stage changed from Unreviewed to Accepted
Note: See TracTickets for help on using tickets.
Back to Top