假设我有一些看起来像这样的模型:
from django.db import models
from django.contrib.auth.models import User
class Author(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
owner = models.ForeignKey(User)
class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
owner = models.ForeignKey(User)
如果我为 Book 模型创建一个 ModelForm,则允许用户从所有作者中进行选择,而不仅仅是他们拥有的作者。我将如何为 Book 模型创建一个 ModelForm,让用户只选择他/她拥有的作者?