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)

これらの2つのテーブルをhtmlテンプレートで1つの順序で表示したいと思っています.djangoは初めてです..私は今学んでいます..plzはviews.pyと「htmlfile.htmlテンプレート」の設計を手伝ってくれます.Plzは与えます私も手続き

4

1 に答える 1

0

最新の質問をチェックして答えを確認してください。

Djangoで外部キー関係を持つ2つのテーブルからデータを取得しますか? django のキー関係

于 2013-03-02T10:49:25.507 に答える