This is my models.py file
from django.db import models
class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
age=models.IntegerField()
class Meta:
db_table=u'Author Info'
def __unicode__(self):
return u"%d %s %s %s" % (self.pk, self.name, self.author.name, self.publisher_name)
def books(self):
return Book.objects.filter(author=self)
class Book(models.Model):
book_name=models.CharField(max_length=30)
publisher_name=models.CharField(max_length=40)
author=models.ForeignKey(Author)
class Meta:
db_table = u'Book Name'
def __unicode__(self):
return u'%d %s %s' % (self.pk, self.first_name, self.last_name)
我想在 django 中显示 2 个表中的数据。请指导我如何编写 views.py 和模板。我在作者表中使用外键