-
Notifications
You must be signed in to change notification settings - Fork 137
Open
Description
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_inlinesMetadata
Metadata
Assignees
Labels
No labels