我有三种模式:
class Film(models.Model):
name = models.CharField("Model Name", max_length=30)
person = models.ManyToManyField(Person, blank=True, through='Association', verbose_name="Associated Person")
class Person(models.Model):
name = models.CharField("Name", max_length=30, unique=True)
long_description = models.TextField("Description of Person", blank=True)
class Association(models.Model):
person = models.ForeignKey(Person, verbose_name = "Person")
film = models.ForeignKey(Film, verbose_name = "Film")
long_description = models.TextField("Description of Association", blank=True)
我正在尝试创建一个表单,允许用户同时添加Person和Association详细信息。因此表单可以读取:
Film: _____________
Person: _________________
Description of Association: ______________________
Description of Person: _____________________
我想我可能应该在Association上使用ModelForm?但是如果我同时添加一个新Person,那么视图需要首先保存Person,然后将m2m链接保存为documentation describes? 我可以通过表单和视图获得一些帮助吗?