Opened 3 years ago

Closed 3 years ago

Last modified 2 years ago

#19555 closed Cleanup/optimization (fixed)

tutorial pt 1 - update year for examples to work

Reported by: rodrigorosa.lg@… Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords: year
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

last part executes:

Choice.objects.filter(pollpub_dateyear=2012)

and now we're in 2013 :)
happy new year!

salú
rela.

Attachments (1)

19555.diff (1.3 KB) - added by timo 3 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 3 years ago by aaugustin

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

Thanks for the report, but docs use various dates between 2005 and now as examples, and it doesn't add much value to change them every year.

comment:2 Changed 3 years ago by claudep

  • Easy pickings set
  • Resolution wontfix deleted
  • Status changed from closed to new
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Cleanup/optimization
  • Version changed from 1.4 to master

As discussed on IRC:

mYk: claudep: mmmm, yeah, we should use a different example then
mYk: filter on a field other than the date

comment:3 Changed 3 years ago by aaugustin

I hadn't noticed that the tutorial created objects with the date set to "now", and then proceeded to filter on the year.

comment:4 Changed 3 years ago by thiagocavila@…

I think this should solve the problem:

Instead of:

from django.utils import timezone
p = Poll(question="What's new?", pub_date=timezone.now())

You make a fix date doing:

from django.utils import timezone
from datetime import datetime
timezone = timezone.get_current_timezone()
p = Poll(question="What's new?", pub_date=datetime(year=2013, month=10, day=10, tzinfo=timezone))

Then the date will be 2013/10/10 forever, no need to change it in 2014 =)

comment:5 Changed 3 years ago by static

Another much simpler solution is to filter by a not hardcoded year:

# Get the poll whose year is current year.

from datetime import datetime
Choice.objects.filter(pollpub_dateyear=datetime.now().year)

<Poll: What's up?>

...

# Find all Choices for any poll whose pub_date is in current year.

Choice.objects.filter(pollpub_dateyear=datetime.now().year)

---

I would also recommend editing the 2012 to 2013, as the 1.5 version is going to be released this year.

Changed 3 years ago by timo

comment:6 Changed 3 years ago by timo

  • Has patch set

I am in favor of keeping the date lookups, since I think it's useful to demo them (plus there aren't really any other fields on Poll to filter by).

The alternative of creating the poll with a specific date or assigning a specific pub_date later as was done before [e0d78f898f] so that the queries aren't dependent on timezone.now() would make the part later in the tutorial that says "If the value of "Date published" doesn't match the time when you created the poll in Tutorial 1, it probably means you forgot to set the correct value for the TIME_ZONE setting" invalid.

Since the images later in the tutorial use 2012, I don't think we should update the shell output for p.pub_date.

comment:7 Changed 3 years ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 99315f709e26ea80de8ea3af4e336dbdbe467711:

Fixed #19555 - Removed '2012' from tutorial 1.

Thanks rodrigorosa.lg and others for the report.

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

In c95ae7729f713a300e67bf30e9506ba78919113a:

[1.5.x] Fixed #19555 - Removed '2012' from tutorial 1.

Thanks rodrigorosa.lg and others for the report.

Backport of 99315f709e from master

comment:9 Changed 3 years ago by Tim Graham <timograham@…>

In 89ba1b27b4442cbb43555f607ab7d0f189a2af50:

[1.4.x] Fixed #19555 - Removed '2012' from tutorial 1.

Thanks rodrigorosa.lg and others for the report.

Backport of 99315f709e from master

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

In c95ae7729f713a300e67bf30e9506ba78919113a:

[1.5.x] Fixed #19555 - Removed '2012' from tutorial 1.

Thanks rodrigorosa.lg and others for the report.

Backport of 99315f709e from master

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