2010-12-15 78 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