Fixed #23148 -- Minor tweaks in tutorial code samples

This commit is contained in:
Collin Anderson 2014-08-01 21:32:53 -04:00 committed by Erik Romijn
parent 8f9d6e83a0
commit e075d2e66b
5 changed files with 13 additions and 7 deletions

View File

@ -66,6 +66,9 @@ After the previous tutorials, our project should look like this::
polls/ polls/
__init__.py __init__.py
admin.py admin.py
migrations/
__init__.py
0001_initial.py
models.py models.py
static/ static/
polls/ polls/

View File

@ -704,8 +704,11 @@ demonstration:
:filename: polls/models.py :filename: polls/models.py
import datetime import datetime
from django.db import models
from django.utils import timezone from django.utils import timezone
# ...
class Question(models.Model): class Question(models.Model):
# ... # ...
def was_published_recently(self): def was_published_recently(self):

View File

@ -275,8 +275,8 @@ with the admin just as we did with ``Question``. That's easy:
:filename: polls/admin.py :filename: polls/admin.py
from django.contrib import admin from django.contrib import admin
from polls.models import Choice from polls.models import Choice, Question
# ...
admin.site.register(Choice) admin.site.register(Choice)
Now "Choices" is an available option in the Django admin. The "Add choice" form Now "Choices" is an available option in the Django admin. The "Add choice" form
@ -319,8 +319,7 @@ registration code to read:
class QuestionAdmin(admin.ModelAdmin): class QuestionAdmin(admin.ModelAdmin):
fieldsets = [ fieldsets = [
(None, {'fields': ['question_text']}), (None, {'fields': ['question_text']}),
('Date information', {'fields': ['pub_date'], ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
'classes': ['collapse']}),
] ]
inlines = [ChoiceInline] inlines = [ChoiceInline]

View File

@ -97,7 +97,7 @@ In the ``polls/urls.py`` file include the following code:
from polls import views from polls import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.index, name='index') url(r'^$', views.index, name='index'),
] ]
The next step is to point the root URLconf at the ``polls.urls`` module. In The next step is to point the root URLconf at the ``polls.urls`` module. In
@ -466,7 +466,7 @@ provides a shortcut. Here's the ``detail()`` view, rewritten:
.. snippet:: .. snippet::
:filename: polls/views.py :filename: polls/views.py
from django.shortcuts import render, get_object_or_404 from django.shortcuts import get_object_or_404, render
from polls.models import Question from polls.models import Question
# ... # ...

View File

@ -72,6 +72,7 @@ create a real version. Add the following to ``polls/views.py``:
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect, HttpResponse from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from polls.models import Choice, Question from polls.models import Choice, Question
# ... # ...
def vote(request, question_id): def vote(request, question_id):