Django

Code

Ticket #4037 (closed: invalid)

Opened 2 years ago

Last modified 2 years ago

need from / import

Reported by: chwolfe Assigned to: jacob
Milestone: Component: Documentation
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

Change History

04/13/07 10:39:24 changed by ubernostrum

  • status changed from new to closed.
  • needs_better_patch changed.
  • resolution set to invalid.
  • needs_tests changed.
  • needs_docs changed.

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/Change #4037 (need from / import)




Change Properties
Action