Error while trying to create a detail page
I've got two classes in my model, like thus:
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 =开发者_JS百科 models.CharField(max_length=200)
salary = models.PositiveIntegerField()
def __unicode__(self):
return self.name
My view looks like this:
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})
I keep getting a FieldError: Cannot resolve keyword 'd' into field. Choices are: id, name, nonprofit, salary, title
I'm a giant noob and can't quite figure out how to fix this. I don't know why it can't resolve it into a field when d equals a field....
Typo:
e = get_object_or_404(executive, d=id)
should be:
e = get_object_or_404(executive, id=id)
精彩评论