Skip to content

Bug: Nested inlines don't work properly with extra=0 #235

Description

@AlexOteiza

Reproduction steps:

  • Create 3 nested models with its inline admin
class Top(models.Model):
    name = models.CharField(max_length=128)

class Middle(models.Model):
    top = models.ForeignKey(Top)
    name = models.CharField(max_length=128)

class Bottom(models.Model):
    middle = models.ForeignKey(Middle)
    name = models.CharField(max_length=128)

class BottomInline(NestedStackedInline):
    extra = 0
    model = Bottom

class MiddleInline(NestedStackedInline):
    model = Middle
    extra = 0
    inlines = [BottomInline]

class TopAdmin(NestedModel):
    model = Top
    inlines = [MiddleInline]
  • Attempt to create a new Top object in django admin.

The Top model creation page has the name field and an empty group of Middle group with zero elements(expected)
But when you add a new Middle there is no Bottom group. (unexpected)
Only after saving one new Middle and re-editing the Top model again, Bottom Group will show (expected).

This does not happen with extra>0 in the BottomInline class

Django version 4.07

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions