Skip to main content

Plugin & Addon Development

Ralph is designed to be extended through plugins and addons without modifying the core codebase. This guide covers different extension mechanisms and best practices.

Extension Methods

Ralph supports several ways to extend functionality:
  1. Custom admin views and tabs - Add new pages to existing models
  2. External Django apps - Integrate standalone Django applications
  3. Entry point hooks - Override specific behaviors via setup.py entry points
  4. Custom filters - Add specialized search and filter capabilities
  5. Signals and receivers - React to events in Ralph

Custom Admin Views

Adding Tabs to Detail Views

Add custom tabs to model detail pages using RalphDetailView or RalphDetailViewAdmin:
Template (myapp/templates/myapp/asset_usage_report.html):
Source: docs/development/addons.md:14-64

Using RalphDetailViewAdmin

For standard admin-style tabs with inlines:
Source: docs/development/addons.md:39-51

Registering Views

Method 1: Via Admin Class (Internal Development)

Use when developing directly in Ralph:
Source: docs/development/addons.md:77-96

Method 2: Via Decorator (External Plugins)

Recommended for external applications and plugins:
Source: docs/development/addons.md:98-114

Template Locations

Templates must be in one of these locations:
  • <model_name>/<view_name>.html
  • <app_label>/<model_name>/<view_name>.html
For example, for BackOfficeAsset model with view name monitoring:
  • backofficeasset/monitoring.html
  • back_office/backofficeasset/monitoring.html
Source: docs/development/addons.md:66-76

Entry Point Hooks

Override Ralph’s internal methods using setuptools entry points.

Defining Entry Points

In your plugin’s setup.py:
Source: docs/development/addons.md:128-146, src/ralph/setup.py:37-53

Implementing Hooks

In your plugin code (myplugin/helpers.py):
Source: docs/development/addons.md:128-165

Available Hooks

Source: docs/development/addons.md:149-153

Configuring Hooks

Activate hooks via environment variables:
Verify active hooks:
Source: docs/development/addons.md:154-165

External Django Apps

Integrate standalone Django applications with Ralph.

Creating a Plugin App

Project structure:

App Configuration

ralph_monitoring/apps.py:

Models

ralph_monitoring/models.py:

Admin Integration

ralph_monitoring/admin.py:

URL Configuration

ralph_monitoring/urls.py:

Installation

setup.py:
Install and configure:

Custom Filters

Create specialized admin filters:

Signals and Event Handlers

React to events in Ralph:

Best Practices

1. Use Decorators for External Plugins

Always use @register_extra_view for external plugins instead of modifying admin classes:

2. Namespace Your URLs and Templates

Avoid conflicts by using consistent naming:

3. Use Entry Points for Behavior Changes

Don’t monkey-patch Ralph code. Use entry points:

4. Follow Ralph Conventions

  • Inherit from Ralph base classes (RalphAdmin, RalphDetailView)
  • Use Ralph mixins (TimeStampMixin, AdminAbsoluteUrlMixin)
  • Follow Ralph’s permission system
  • Use Ralph’s form and widget classes

5. Handle Dependencies

Declare Ralph as a dependency:

6. Provide Documentation

Include README with:
  • Installation instructions
  • Configuration options
  • Usage examples
  • Dependencies
  • License information

Example Plugin Package

Complete example of a monitoring plugin:
The plugin provides:
  • Custom tab on asset detail pages showing real-time metrics
  • Admin interface for historical metrics
  • API endpoint for pushing metrics from external systems
  • Dashboard view for monitoring overview
  • Signal handlers for automatic metric collection

Next Steps