Django - набор форм, работающий с несколькими формами

<
models.py

class Parent(models.Model):
    parent_name = models.CharField(max_length=20)

class Child(models.Model):
    child_name = models.CharField(max_length=20)
    parent = models.ForeignKey("Parent",on_delete=models.PROTECT)
    birth_place = models.OneToOneField("BirthPlace", on_delete=models.PROTECT)

class BirthPlace(models.Model):
    place_name = models.CharField(max_length=20)





forms.py

ChildrenFormset = inlineformset_factory(Parent, Child, fields='__all__', extra=0)

< <
def add_fields(self, form, index):
    super(ChildrenFormset, self).add_fields(form, index)

    form.initial['birth_place_name']=form.instance.birthplace.place_name
< <
Вернуться на верх