Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#21418 closed Uncategorized (worksforme)

In tutorial02 the was_published_recently section of the example may be defective?

Reported by: zjooji+django@… Owned by: nobody
Component: Documentation Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hey,

I was going through part 2 of the tutorial and I ran into some errors when I was doing the was_published_recently section of the tutorial.

Firstly, the debugger kept telling me

was_published_recently() takes exactly 1 argument (2 given)

I was able to overcome that by adding a second argument to the was_published_recently function.

After that there were some missing import statements for timezone and datetime I needed to add.

And finally the code

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

Had to be changed to

def was_published_recently(self, arg2)
    return arg2.pub_date >= timezone.now() - datetime.timedelta(days=1)

After all these changes, the example ran and appeared to be working as shown in the screenshot.

In case you are wondering I did check my django version and it is in fact 1.6

Apologies if I have made some obvious newb mistake and have caused some of this myself. Either way the import statements should probably be added to save people having to find them for themselves

Change History (2)

comment:1 by Baptiste Mispelon, 11 years ago

Resolution: worksforme
Status: newclosed

Hi,

I just checked and everything seems in working order to me.
The was_published_recently method is defined in the first part of the tutorial [1] and that section includes the relevant imports (it's omitted in the second part for brevity's sake).

There's no reason to add a second argument to the method.
I think you're getting confused by python's automatic passing of the current instance when calling a method.
There's more information on this topic in the official python tutorial [2] (which is a great introduction to python by the way).

If things still aren't working for you, don't hesitate to turn to our support channels [3].
Beginners are always welcome there.

[1] https://docs.djangoproject.com/en/1.6/intro/tutorial02/
[2] http://docs.python.org/2/tutorial/classes.html#method-objects
[3] https://docs.djangoproject.com/en/1.6/faq/help/#how-do-i-do-x-why-doesn-t-y-work-where-can-i-go-to-get-help

comment:2 by Tim Graham <timograham@…>, 11 years ago

In 6c5f5b9a414b8bdfafc45db5710acf200cca9885:

Fixed typo in tutorial 2; refs #21418.

Note: See TracTickets for help on using tickets.
Back to Top