Opened 8 years ago

Closed 8 years ago

Last modified 8 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



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 >= - datetime.timedelta(days=1)

Had to be changed to

def was_published_recently(self, arg2)
    return arg2.pub_date >= - 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 Changed 8 years ago by Baptiste Mispelon

Resolution: worksforme
Status: newclosed


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.


comment:2 Changed 8 years ago by Tim Graham <timograham@…>

In 6c5f5b9a414b8bdfafc45db5710acf200cca9885:

Fixed typo in tutorial 2; refs #21418.

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