django-polymorphic inline admin with many to many relation
Asked Answered
E

1

8

Is it possible for a model with many to many relation to a polymorphic model to display stacked inline forms (depending on the type of the child model) ?

Using the example from the django-polymorphic docs i'm trying to make the list of ModelA models to display as admin.StackedInline in the RelatingModel admin page, each with it's specific form.

Exon answered 11/9, 2015 at 8:50 Comment(0)
N
0

First, you need to define your inline class base on your related model

class MyMode1lInline(admin.TabularInline):
    model = MyModel1
    extra = 1

Now you need to connect your inline to the PolymorphicChildModelAdmin

polymorphic_models = (MyModel1, MyModel2, MyModel3)
for child in polymorphic_models:
    @admin.register(child)
    class PolymorphicChildModelAdmin2(PolymorphicChildModelAdmin):
        if child == MyModel1:
            inlines = [MyMode1lInline]
        base_model = child
        show_in_index = False
Necolenecro answered 16/8, 2022 at 14:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.