我的models.py如下:
from django.db import models
class Book(models.Model):
book_id=models.AutoField(primary_key=True,unique=True)
book_name=models.CharField(max_length=30)
author_name=models.CharField(max_length=30)
publisher_name=models.CharField(max_length=40)
def __unicode__(self):
return "%d %s %s %s" % (self.book_id,self.book_name, self.author_name,self.publisher_name)
class Author(models.Model):
author_id=models.AutoField(primary_key=True)
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
age=models.IntegerField()
book=models.ForeignKey(Book)
def __unicode__(self):
return u'%d %s %s' % (self.author_id,self.first_name, self.last_name)
我的views.py是这样的:
def index(request):
books = Book.objects.all()
context={'books':books}
return render(request,'index.html', context)
上面的views.py 显示了Book 类中的内容,但是我无法显示author 表中的内容。我的要求是在一个页面中显示合并的两个内容。请帮我做这件事。