dango One2Many example

from django.db import models

class Person(models.Model):
    name=models.CharField('作者姓名',max_length=10)
    age=models.IntegerField('作者年龄')

class Book(models.Model):
    person=models.ForeignKey(Person, related_name='person_book')
    title = models.CharField('书籍名称', max_length=10)
    pubtime = models.DateField('出版时间')

person=Person.objects.filter(name='leon')
bookdict=person.person_book.all()#note the related_name use
#bookdict=person.book_set().all()


book=Book.objects().filter(age=32)
author=book.person

你可能感兴趣的:(example)