2010-12-15 70 views
0

我已經在我的模型有兩個班,像這樣的:錯誤嘗試創建一個詳細信息頁面

from django.db import models 

class nonprofit(models.Model): 
    organization = models.CharField(max_length=200) 
    city = models.CharField(max_length=200) 
    website = models.URLField(max_length=120, blank=True) 
    ........ 

    def __unicode__(self): 
     return self.organization 

class executive(models.Model): 
    nonprofit = models.ForeignKey(nonprofit) 
    name = models.CharField(max_length=200) 
    title = models.CharField(max_length=200) 
    salary = models.PositiveIntegerField() 

    def __unicode__(self): 
     return self.name 

我的看法是這樣的:

from django.shortcuts import render_to_response, get_object_or_404 
from nonprofit.models import executive 

def index(request): 
    executives = executive.objects.all() 
    return render_to_response('nonprofit/index.html', {'executives': executives}) 

def detail(request, id): 
    e = get_object_or_404(executive, d=id) 
    return render_to_response('nonprofit/detail.html', {'executives': e}) 

我不斷收到一個FieldError: 無法將關鍵字'd'解析爲字段。選擇是:身份證,名稱,非營利組織,工資,標題

我是一個巨型noob,不能完全弄清楚如何解決這個問題。我不知道爲什麼,當d等於一個字段它無法解析成一個領域....

回答

1

錯字:

e = get_object_or_404(executive, d=id) 

應該是:

e = get_object_or_404(executive, id=id) 
+0

謝謝!看起來它應該是'高管'而不是'高管'。作爲一個noob,小錯別字只是現在殺死我。 – Matt 2010-12-16 01:22:21