Skip to content

Library does not support Django's get_inlines method. #155

@PedroPerpetua

Description

@PedroPerpetua

Django inlines traditionally use the method get_inlines to retrieve the list of inlines in a model, in case the user needs to conditionally decide which inlines to render.

Even though the Nested inlines inherit from Django's ModelAdmin, they do not appear to support this method. Specifically, the InlineInstancesMixin should change from self.inlines to self.get_inlines() in order to support this method.

Here's the work around I'm currently using:

class MyModelAdmin(NestedModelAdmin):
    def get_inline_instances(
        self, 
        request: HttpRequest, 
        instance: Optional[MyModel] = None
    ) -> Iterable[admin.options.InlineModelAdmin]:
        """Override this method to set the inlines before calling the get_inline_instances"""
        self.inlines = self.get_inlines(request, instance)
        return super().get_inline_instances(request, instance)

    def get_inlines(
        self, 
        request: HttpRequest,  
        instance: MyModel
    ) -> Iterable[admin.options.InlineModelAdmin]:
        # Custom logic that returns a list of Inlines to be rendered
        return list_of_inlines

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions