OskarPersson / django-nested-inline

Nested inline support for Django admin
MIT License
341 stars 136 forks source link

When saving a new top level of a nested table - Changing a field and saving twice is required. #46

Open lukedupin opened 8 years ago

lukedupin commented 8 years ago

When creating a new nested table, after clicking the Add new, at least one field needs to be changed, and "save and continue" must be clicked twice before a save happens.

Can I throw you guys a couple hundred bucks to fix these?

herrri commented 8 years ago

+1

Having the same issue.

herrri commented 8 years ago

Did some digging. The saving breaks if there is multilevel nesting and the extra attribute in NestedStackedInline is set to 0. It means that the sub-sub-level forms do not get created. Attached some code to reproduce:

# models.py
from django.db import models

class A(models.Model):
    content = models.CharField(max_length=255)

class B(models.Model):
    content = models.CharField(max_length=255)
    a = models.ForeignKey(A)

class C(models.Model):
    content = models.CharField(max_length=255)
    b = models.ForeignKey(B)
#admin.py

from django.contrib import admin
from nested_inline.admin import NestedStackedInline, NestedModelAdmin
from someapp.models import A, B, C

class CAdmin(NestedStackedInline):
    model = C
    extra = 1

class BAdmin(NestedStackedInline):
    model = B
    inlines = [CAdmin]
    extra = 0 #  <-- This breaks the formset generation

class AAdmin(NestedModelAdmin):
    inlines = [BAdmin]
    model = A

admin.site.register(A, AAdmin)

I'll be more than happy to take part in solving this.

lukedupin commented 8 years ago

Nice find.

I ended up switching my nested plugin over to: django-nested-admin (2.1.8)

It doesn't support Tabular inline which is a shame, but it seems to work reliably otherwise.