Updated tutorial to use explicit relative imports.

This commit is contained in:
Tim Graham 2015-02-22 09:59:56 -05:00
parent ff5e47e7a4
commit b2f331dc68
4 changed files with 24 additions and 17 deletions

View File

@ -113,7 +113,8 @@ file, and edit it to look like this:
:filename: polls/admin.py
from django.contrib import admin
from polls.models import Question
from .models import Question
admin.site.register(Question)
@ -193,7 +194,8 @@ the ``admin.site.register(Question)`` line with:
:filename: polls/admin.py
from django.contrib import admin
from polls.models import Question
from .models import Question
class QuestionAdmin(admin.ModelAdmin):
@ -221,7 +223,8 @@ up into fieldsets:
:filename: polls/admin.py
from django.contrib import admin
from polls.models import Question
from .models import Question
class QuestionAdmin(admin.ModelAdmin):
@ -248,7 +251,8 @@ aren't commonly used:
:filename: polls/admin.py
from django.contrib import admin
from polls.models import Question
from .models import Question
class QuestionAdmin(admin.ModelAdmin):
@ -277,7 +281,8 @@ with the admin just as we did with ``Question``. That's easy:
:filename: polls/admin.py
from django.contrib import admin
from polls.models import Choice, Question
from .models import Choice, Question
# ...
admin.site.register(Choice)
@ -310,7 +315,8 @@ registration code to read:
:filename: polls/admin.py
from django.contrib import admin
from polls.models import Choice, Question
from .models import Choice, Question
class ChoiceInline(admin.StackedInline):

View File

@ -94,7 +94,7 @@ In the ``polls/urls.py`` file include the following code:
from django.conf.urls import url
from polls import views
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
@ -209,7 +209,7 @@ Wire these new views into the ``polls.urls`` module by adding the following
from django.conf.urls import url
from polls import views
from . import views
urlpatterns = [
# ex: /polls/
@ -296,7 +296,7 @@ commas, according to publication date:
from django.http import HttpResponse
from polls.models import Question
from .models import Question
def index(request):
@ -374,7 +374,7 @@ Now let's update our ``index`` view in ``polls/views.py`` to use the template:
from django.http import HttpResponse
from django.template import RequestContext, loader
from polls.models import Question
from .models import Question
def index(request):
@ -406,7 +406,7 @@ rewritten:
from django.shortcuts import render
from polls.models import Question
from .models import Question
def index(request):
@ -436,7 +436,7 @@ for a given poll. Here's the view:
from django.http import Http404
from django.shortcuts import render
from polls.models import Question
from .models import Question
# ...
def detail(request, question_id):
try:
@ -471,7 +471,7 @@ provides a shortcut. Here's the ``detail()`` view, rewritten:
from django.shortcuts import get_object_or_404, render
from polls.models import Question
from .models import Question
# ...
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)

View File

@ -73,7 +73,7 @@ create a real version. Add the following to ``polls/views.py``:
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from polls.models import Choice, Question
from .models import Choice, Question
# ...
def vote(request, question_id):
p = get_object_or_404(Question, pk=question_id)
@ -225,7 +225,7 @@ First, open the ``polls/urls.py`` URLconf and change it like so:
from django.conf.urls import url
from polls import views
from . import views
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
@ -254,7 +254,7 @@ views and use Django's generic views instead. To do so, open the
from django.core.urlresolvers import reverse
from django.views import generic
from polls.models import Choice, Question
from .models import Choice, Question
class IndexView(generic.ListView):

View File

@ -170,7 +170,8 @@ Put the following in the ``tests.py`` file in the ``polls`` application:
from django.utils import timezone
from django.test import TestCase
from polls.models import Question
from .models import Question
class QuestionMethodTests(TestCase):