0

私はこのdjangoアプリを作成しています。これは投票アプリなので、質問が表示され、質問をクリックすると選択肢が表示されます。このチュートリアルを使用しています https://docs.djangoproject.com/en/1.4/intro/tutorial03 /

表示されるエラーは、質問をクリックしても選択肢が表示されません。 ここに画像の説明を入力

しかし、それは私の管理ページに表示されます ここに画像の説明を入力

私の detail.html テンプレートは

<h1>{{ poll.question }}</h1>
<ul>
{% for choice in poll.choice_set.all %}
    <li>{{ choice.choice }}</li>
{% endfor %}
</ul>

私のviews.pyは

from django.http import HttpResponse
from myapp.models import Poll ,choice
from django.template import Context, loader
from django.http import Http404
from django.shortcuts import render_to_response, get_object_or_404


def index(request):
    latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
    return render_to_response('myapp/index.html', {'latest_poll_list':     latest_poll_list})



def results(request, poll_id):
    return HttpResponse("You're looking at the results of poll %s." % poll_id)

def vote(request, poll_id):
    return HttpResponse("You're voting on poll %s." % poll_id)

def detail(request, poll_id):
    p = get_object_or_404(Poll, pk=poll_id)
    return render_to_response('myapp/detail.html', {'poll': p})

私のモデルは次のとおりです。

from django.db import models
from django.contrib import admin
class Poll(models.Model):
    question=models.CharField(max_length=200)
    pub_date=models.DateTimeField('date published')
    def __unicode__(self):
        return self.question



# Create your models here.
class choice(models.Model):
    poll=models.ForeignKey(Poll)
    choice_text=models.CharField(max_length=200)
    votes=models.IntegerField(default=0)
    def __unicode__(self):
        return self.choice_text
class ChoiceInline(admin.TabularInline):
    model = choice 
    extra = 3
class PollAdmin(admin.ModelAdmin):
    fields = ['pub_date','question']
    inlines=[ChoiceInline]
    list_display =('question','pub_date')
    list_filter=['pub_date']
    search_fields=['question']
    #date_hierarchy='pub_date'

これの直し方がわからない(笑)

4

1 に答える 1