From ddc1e0c0fbd9b8b1851d47f2e535e8c2a5b941f6 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sun, 22 Feb 2015 09:59:56 -0500 Subject: [PATCH] [1.8.x] Updated tutorial to use explicit relative imports. Backport of b2f331dc68ec3c5a34285f7af9614e4178e9a371 from master --- docs/intro/tutorial02.txt | 18 ++++++++++++------ docs/intro/tutorial03.txt | 14 +++++++------- docs/intro/tutorial04.txt | 6 +++--- docs/intro/tutorial05.txt | 3 ++- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/docs/intro/tutorial02.txt b/docs/intro/tutorial02.txt index 3dacc62369..22c37d7b7e 100644 --- a/docs/intro/tutorial02.txt +++ b/docs/intro/tutorial02.txt @@ -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): diff --git a/docs/intro/tutorial03.txt b/docs/intro/tutorial03.txt index 83ed0cff70..cf0d4dedf5 100644 --- a/docs/intro/tutorial03.txt +++ b/docs/intro/tutorial03.txt @@ -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) diff --git a/docs/intro/tutorial04.txt b/docs/intro/tutorial04.txt index 2169d5207c..fcacf971cb 100644 --- a/docs/intro/tutorial04.txt +++ b/docs/intro/tutorial04.txt @@ -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): diff --git a/docs/intro/tutorial05.txt b/docs/intro/tutorial05.txt index 545a84ad80..ab8b28bdf4 100644 --- a/docs/intro/tutorial05.txt +++ b/docs/intro/tutorial05.txt @@ -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):