jazzband / django-polymorphic

Improved Django model inheritance with automatic downcasting
https://django-polymorphic.readthedocs.io
Other
1.64k stars 280 forks source link

An inline within an inline #581

Open lyaguxafrog opened 7 months ago

lyaguxafrog commented 7 months ago

I wanted to make an inline inside the inline, but I didn't understand how to do it, I tried something like this:

class ContentBlockAdmin(StackedPolymorphicInline):

    class Left_text(StackedPolymorphicInline.Child):
        model = ScreenTextBlock_left

    class Left_image(StackedPolymorphicInline.Child):
        model = ScreenImageBlock_left

    model = ContentBlock
    child_inlines = (
        Left_text,
        Left_image
    )

class ScreenInline(PolymorphicInlineSupportMixin, admin.StackedInline):
    model = Screens
    extra = 0
    inlines = (ContentBlockAdmin, )

class PracticumAdmin(admin.ModelAdmin):
    inlines = (ScreenInline, )

admin.site.register(Practicum, PracticumAdmin)
j-antunes commented 7 months ago

What is the error that you are seeing?

piranna commented 7 months ago

I'm in a similar situation, but I get no error at all. Before I had a single childs level and I think it worked, but once I splitted the parent model so now there are two levels, I don't have inlines at all.

j-antunes commented 7 months ago

@piranna - Can you provide a reproducible example?

piranna commented 7 months ago

@piranna - Can you provide a reproducible example?

It's private code, but will try to get something. If you want to try, I have parentA class with some fields, childB with no fields, and grandChildC with some fields. If I set grandChildC as direct child of parentA, I think to remember they grandChildC fields were shown, but if I put the intermediate childB class with no fields, no fields of grandChildC are shown.

j-antunes commented 7 months ago

@piranna - Are you able to extract part of the code and change the variables names, etc... You can call the class A B C, so we can have something to test against.

lyaguxafrog commented 7 months ago

What is the error that you are seeing?

there are no errors, just nothing is displayed in the admin panel.