1

嗨,我有这样的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)

我想在 html 模板中以单一顺序显示这两个表。我是 django 的新手..我现在正在学习..请帮助我设计 views.py 和“htmlfile.html 模板”。请给我的程序也

4

1 回答 1

0

check your latest question for answer,

Retrieve data from two tables with foreign key relationship in Django? key-relationship-in-django

于 2013-03-02T10:49:25.507 回答