#19555 closed Cleanup/optimization (fixed)
tutorial pt 1 - update year for examples to work
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | dev |
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)
Change History (11)
comment:1 by , 12 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 12 years ago
Easy pickings: | set |
---|---|
Resolution: | wontfix |
Status: | closed → new |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
Version: | 1.4 → 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 by , 12 years ago
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 by , 12 years ago
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 by , 12 years ago
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.
by , 12 years ago
Attachment: | 19555.diff added |
---|
comment:6 by , 12 years ago
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 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → 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.