Search code examples
pythondjangonestedinlinedjango-grappelli

Django Grappelli_Nested Inlines cannot create new nested lines after initial load


I am looking for a way to create a new nested row, before saving the "owner"-row. By way of django ticket 9025 I found Grappelli-Nested-Inlines which I have been using.

I have a test project set up based on the instructions found at that link:

from django.contrib import admin
from grappelli_nested.admin import NestedModelAdmin, NestedStackedInline, NestedTabularInline
from .models import *

class MyNestedInline(NestedTabularInline):
model = C
extra = 0

class MyInline(NestedStackedInline):
model = B
extra = 0
inlines = [MyNestedInline,]

class MyAdmin(NestedModelAdmin):
inlines = [MyInline,]

admin.site.register(A, MyAdmin)

My issue is based in the fact that I cannot create a child object before saving the parent. That is to say, the "add another c"-button has no functionality before saving B

Is there a way to achieve this?

I have read through all the posts regarding this that I could find, but I have to say that if the answer is included anywhere, then I didn´t understand it, so please be patient with me.

I should also note, that because of the production code, grappelli is a requirement, so anything that clashes with that will not work.


Solution

  • What i did was to take the templates that django-grappelli-inline provides and use them for use as a template in django-nested-inlines.

    class NestedStackedInline(NestedInline):
        template = 'admin/edit_inline/stacked.html'
    
    class NestedTabularInline(NestedInline):
        template = 'admin/edit_inline/tabular.html'
    

    Where the templates are the ones from django-grappelli-inline