Code

Opened 7 years ago

Closed 7 years ago

#4037 closed (invalid)

need from / import

Reported by: chwolfe Owned by: jacob
Component: Documentation Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In the section in tutorial one,

import datetime

# ...
class Poll(models.Model):

# ...
def was_published_today(self):

return self.pub_date.date() == datetime.date.today()

I think the import line should be:

from datetime import datetime

I am somewhat new to python so maybe I'm doing something wrong.

Attachments (0)

Change History (1)

comment:1 Changed 7 years ago by ubernostrum

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

No, it's correct. The Python standard module datetime contains classes named datetime and date. Doing import datetime makes datetime the _module_ available to you, so the two classes need to be referred to as datetime.datetime and datetime.date.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.