You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
classMyModelAdmin(NestedModelAdmin):
defget_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)
returnsuper().get_inline_instances(request, instance)
defget_inlines(
self,
request: HttpRequest,
instance: MyModel
) ->Iterable[admin.options.InlineModelAdmin]:
# Custom logic that returns a list of Inlines to be renderedreturnlist_of_inlines
The text was updated successfully, but these errors were encountered:
PedroPerpetua
changed the title
Library does not supper the get_inlines method.
Library does not support Django's get_inlines method.
Aug 4, 2023
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, theInlineInstancesMixin
should change fromself.inlines
toself.get_inlines()
in order to support this method.Here's the work around I'm currently using:
The text was updated successfully, but these errors were encountered: