Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PedroPerpetua opened this issue Aug 4, 2023 · 0 comments
Open

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

PedroPerpetua opened this issue Aug 4, 2023 · 0 comments

Comments

@PedroPerpetua
Copy link

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
@PedroPerpetua PedroPerpetua changed the title Library does not supper the get_inlines method. Library does not support Django's get_inlines method. Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant