nyergler / nested-formset

Nest Django formsets for multi-level editing.
BSD 3-Clause "New" or "Revised" License
87 stars 21 forks source link

Another inline level? #3

Closed csarcom closed 10 years ago

csarcom commented 10 years ago

It`s possible to have another level of inlines? Something like:

class Block(models.Model):
    description = models.CharField(max_length=255)

class Building(models.Model):
    block = models.ForeignKey(Block)
    address = models.CharField(max_length=255)

class Tenant(models.Model):
    building = models.ForeignKey(Building)
    name = models.CharField(max_length=255)
    unit = models.CharField(
        blank=False,
        max_length=255,
    )

class Contact(models.Model):
    tenant = models.ForeignKey(Tenant)
    email = models.CharField(max_length=50)
    phone = models.CharField(max_length=50)
mbertheau commented 10 years ago

It should work with this form:

nestedformset_factory(
    models.Block,
    models.Building,
    nested_formset=nestedformset_factory(
        models.Building,
        models.Tenant,
        nested_formset=inlineformset_factory(
            models.Tenant,
            models.Contact
        )
    )
)
csarcom commented 10 years ago

Perfect! :+1: