Kaydet (Commit) b2f331dc authored tarafından Tim Graham's avatar Tim Graham

Updated tutorial to use explicit relative imports.

üst ff5e47e7
...@@ -113,7 +113,8 @@ file, and edit it to look like this: ...@@ -113,7 +113,8 @@ file, and edit it to look like this:
:filename: polls/admin.py :filename: polls/admin.py
from django.contrib import admin from django.contrib import admin
from polls.models import Question
from .models import Question
admin.site.register(Question) admin.site.register(Question)
...@@ -193,7 +194,8 @@ the ``admin.site.register(Question)`` line with: ...@@ -193,7 +194,8 @@ the ``admin.site.register(Question)`` line with:
:filename: polls/admin.py :filename: polls/admin.py
from django.contrib import admin from django.contrib import admin
from polls.models import Question
from .models import Question
class QuestionAdmin(admin.ModelAdmin): class QuestionAdmin(admin.ModelAdmin):
...@@ -221,7 +223,8 @@ up into fieldsets: ...@@ -221,7 +223,8 @@ up into fieldsets:
:filename: polls/admin.py :filename: polls/admin.py
from django.contrib import admin from django.contrib import admin
from polls.models import Question
from .models import Question
class QuestionAdmin(admin.ModelAdmin): class QuestionAdmin(admin.ModelAdmin):
...@@ -248,7 +251,8 @@ aren't commonly used: ...@@ -248,7 +251,8 @@ aren't commonly used:
:filename: polls/admin.py :filename: polls/admin.py
from django.contrib import admin from django.contrib import admin
from polls.models import Question
from .models import Question
class QuestionAdmin(admin.ModelAdmin): class QuestionAdmin(admin.ModelAdmin):
...@@ -277,7 +281,8 @@ with the admin just as we did with ``Question``. That's easy: ...@@ -277,7 +281,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, Question
from .models import Choice, Question
# ... # ...
admin.site.register(Choice) admin.site.register(Choice)
...@@ -310,7 +315,8 @@ registration code to read: ...@@ -310,7 +315,8 @@ registration code to read:
:filename: polls/admin.py :filename: polls/admin.py
from django.contrib import admin from django.contrib import admin
from polls.models import Choice, Question
from .models import Choice, Question
class ChoiceInline(admin.StackedInline): class ChoiceInline(admin.StackedInline):
......
...@@ -94,7 +94,7 @@ In the ``polls/urls.py`` file include the following code: ...@@ -94,7 +94,7 @@ In the ``polls/urls.py`` file include the following code:
from django.conf.urls import url from django.conf.urls import url
from polls import views from . import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
...@@ -209,7 +209,7 @@ Wire these new views into the ``polls.urls`` module by adding the following ...@@ -209,7 +209,7 @@ Wire these new views into the ``polls.urls`` module by adding the following
from django.conf.urls import url from django.conf.urls import url
from polls import views from . import views
urlpatterns = [ urlpatterns = [
# ex: /polls/ # ex: /polls/
...@@ -296,7 +296,7 @@ commas, according to publication date: ...@@ -296,7 +296,7 @@ commas, according to publication date:
from django.http import HttpResponse from django.http import HttpResponse
from polls.models import Question from .models import Question
def index(request): def index(request):
...@@ -374,7 +374,7 @@ Now let's update our ``index`` view in ``polls/views.py`` to use the template: ...@@ -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.http import HttpResponse
from django.template import RequestContext, loader from django.template import RequestContext, loader
from polls.models import Question from .models import Question
def index(request): def index(request):
...@@ -406,7 +406,7 @@ rewritten: ...@@ -406,7 +406,7 @@ rewritten:
from django.shortcuts import render from django.shortcuts import render
from polls.models import Question from .models import Question
def index(request): def index(request):
...@@ -436,7 +436,7 @@ for a given poll. Here's the view: ...@@ -436,7 +436,7 @@ for a given poll. Here's the view:
from django.http import Http404 from django.http import Http404
from django.shortcuts import render from django.shortcuts import render
from polls.models import Question from .models import Question
# ... # ...
def detail(request, question_id): def detail(request, question_id):
try: try:
...@@ -471,7 +471,7 @@ provides a shortcut. Here's the ``detail()`` view, rewritten: ...@@ -471,7 +471,7 @@ provides a shortcut. Here's the ``detail()`` view, rewritten:
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from polls.models import Question from .models import Question
# ... # ...
def detail(request, question_id): def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id) question = get_object_or_404(Question, pk=question_id)
......
...@@ -73,7 +73,7 @@ create a real version. Add the following to ``polls/views.py``: ...@@ -73,7 +73,7 @@ create a real version. Add the following to ``polls/views.py``:
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 .models import Choice, Question
# ... # ...
def vote(request, question_id): def vote(request, question_id):
p = get_object_or_404(Question, pk=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: ...@@ -225,7 +225,7 @@ First, open the ``polls/urls.py`` URLconf and change it like so:
from django.conf.urls import url from django.conf.urls import url
from polls import views from . import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'), 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 ...@@ -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.core.urlresolvers import reverse
from django.views import generic from django.views import generic
from polls.models import Choice, Question from .models import Choice, Question
class IndexView(generic.ListView): class IndexView(generic.ListView):
......
...@@ -170,7 +170,8 @@ Put the following in the ``tests.py`` file in the ``polls`` application: ...@@ -170,7 +170,8 @@ Put the following in the ``tests.py`` file in the ``polls`` application:
from django.utils import timezone from django.utils import timezone
from django.test import TestCase from django.test import TestCase
from polls.models import Question from .models import Question
class QuestionMethodTests(TestCase): class QuestionMethodTests(TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment