If you’ve already extended a HorillaListView from a separate app using _inherit_list (see the previous post), the next natural question is whether the same pattern works for tabs. It does Horilla CRM ships a parallel mechanism, _inherit_tab, built specifically for HorillaTabView . It lets an extension app add a tab to an existing tab bar a settings page, a shell view without editing the view that defines it.
One thing worth being upfront about: unlike _inherit_list, which custom_fields already uses in production to inject custom-field context into every list view, _inherit_tab currently has no production consumer in this codebase. It’s fully implemented, tested, and documented it was introduced as infrastructure in Horilla 1.14.0 but nothing ships with it wired up yet. That doesn’t make it less real; it just means the example below is the mechanism’s own documented reference case rather than something copied from a live app. It’s also a good reason to understand its one real limitation before reaching for it.
What Does the Extension Mechanism Do?
_inherit_tab lets a TabExtension subclass in a separate app:
- Override get_tabs() on a specific HorillaTabView subclass
- Call the original implementation and append, remove, or reorder tab entries
- Get composed in automatically, the same way _inherit_list is no edits to the target view, no URL changes
Structurally it’s the twin of _inherit_list: a registry, a per-request resolver hooked into as_view(), and dynamic MRO composition. The one real difference and it matters is what kind of target it can be registered against.
Defining a Tab Extension
An extension is a TabExtension subclass with _inherit_tab set to the dotted path of the view being extended:
# myapp/tabs.py
from horilla.extension.tab import TabExtension
from horilla.contrib.core.views.branches import CompanyInformationTabView
from horilla.urls import reverse_lazy
from horilla.utils.translation import gettext_lazy as _
class MyCompanyInfoTab(TabExtension):
_inherit_tab = "horilla.contrib.core.views.branches.CompanyInformationTabView"
_inherit_tab_priority = 100
def get_tabs(self):
tabs = list(CompanyInformationTabView.get_tabs(self))
if self.request.user.has_perm("myapp.view_thing"):
tabs.append(
{
"title": _("My Tab"),
"url": reverse_lazy("myapp:my_tab"),
"target": "my-tab-content",
"id": "my-tab-view",
}
)
return tabs
As with list extensions, the moment this class body runs, TabExtension.__init_subclass__ notices _inherit_tab is set and registers it no manual wiring.
Registering the Extension App
Same convention as every other extension kind: add the module to auto_import_modules so AppLauncher.ready() imports it on startup.
myapp/apps.py
class MyAppConfig(AppLauncher):
name = “myapp”
auto_import_modules = […, “tabs”]
You still register your own URL for the new tab’s content (myapp:my_tab above) the normal way. And in the host app, nothing changes CompanyInformationTabView.as_view() keeps being called from urls.py exactly as before; the composed version is swapped in transparently at request time.
How Resolution Works
HorillaTabView.as_view() wraps the view in a resolver, the same shape as the list mechanism:
def view(request, *args, **kwargs):
resolved = resolve_tab_view_class(cls)
if resolved is not cls:
if (
getattr(view, "_extended_handler", None) is None
or getattr(view, "_extended_cls", None) is not resolved
):
view._extended_cls = resolved
view._extended_handler = resolved.as_view(**initkwargs)
return view._extended_handler(request, *args, **kwargs)
return base_view(request, *args, **kwargs)
resolve_tab_view_class() looks up registered extensions for the exact target path and, if any exist, returns a dynamically composed class instead:
CompanyInformationTabViewExtended -> MyCompanyInfoTab -> CompanyInformationTabView -> HorillaTabView
The One Important Limitation: No Base-Class Fallback
This is the detail that actually matters if you’re choosing between _inherit_tab and Horilla’s other extension points. _inherit_list’s resolver, when it can’t find an exact match for a concrete view, walks that view’s MRO and checks whether any of its base classes have a registration which is how custom_fields manages to extend every list view at once by registering against the shared HorillaListView base.
_inherit_tab’s resolver does not do this. It’s a flat, exact lookup:
path = _tab_view_path(view_class)
composed = TAB_COMPOSED_MAP.get(path)
result = composed if composed is None else view_class
Register _inherit_tab against HorillaTabView itself, hoping it’ll apply to every tab view in the app, and it simply won’t be picked up by anything. The target has to be one concrete subclass a specific settings page, a specific shell view.
This is exactly why Horilla’s own record-detail tab injections (adding a “Cadence” tab or a “Potential Duplicates” tab to every Lead/Opportunity/Account detail page) don’t use _inherit_tab at all. They use the sibling _inherit_view mechanism instead, targeting the shared HorillaDetailTabView base because that resolver does support the MRO fallback:
class CadenceTabExtension(ViewExtension):
_inherit_view = "horilla.contrib.generics.views.detail_tabs.HorillaDetailTabView"
def _prepare_detail_tabs(self):
super()._prepare_detail_tabs()
self.tabs.append({...})
So the practical rule of thumb is: use _inherit_tab for a one-off tab added to one specific settings/shell page; use _inherit_view against HorillaDetailTabView when you want a tab to show up on every record-detail page across the app.
No Declarative Layout Hooks — Method Overrides Only
List extensions have declarative hooks like columns_insert and bulk_update_fields_append static data describing an additive change, merged in automatically. Tab extensions don’t have an equivalent tabs_insert/tabs_append. Every tab extension works by overriding get_tabs() in Python and manipulating the returned list directly, as in the example above.
If you want tab ordering or conditional inclusion, that logic lives in your override, not in a declared hook.
_inherit_tab gives you the same shape of extension app you’d write for a list view a TabExtension subclass, registered via auto_import_modules, composed in automatically at request time but scoped to one concrete HorillaTabView subclass at a time, with no base-class fan-out and no declarative layout hooks.
For a single settings page that needs one more tab, it’s a clean, minimal-footprint tool. For something that needs to show up across every record’s detail view, reach for _inherit_view against HorillaDetailTabView instead, which is what Horilla’s own cadence and duplicate-detection features already do.