2013-03-02 76 views
1

嗨,我有這樣的顯示多個相關Django模型

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) 

我waant在HTML template.I是新來的Django以顯示一個訂單這兩個表的models.py。 。我正在學習now..plz幫我views.py的設計和「htmlfile.html模板」 .Plz給我的程序也

+0

檢查您的最新問題的答案, http://stackoverflow.com/questions/15173251/retrieve-data-from-two-tables-with-foreign- 鍵關係型-的Django – gangakvp 2013-03-02 10:48:23

回答